java.lang.Character.compareTo()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(5.3k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中java.lang.Character.compareTo()方法的一些代码示例,展示了Character.compareTo()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Character.compareTo()方法的具体详情如下:
包路径:java.lang.Character
类名称:Character
方法名:compareTo

Character.compareTo介绍

[英]Compares this object to the specified character object to determine their relative order.
[中]将此对象与指定的字符对象进行比较,以确定其相对顺序。

代码示例

代码示例来源:origin: medcl/elasticsearch-analysis-ik

/**
 * 实现Comparable接口
 * @param o
 * @return int
 */
public int compareTo(DictSegment o) {
  //对当前节点存储的char进行比较
  return this.nodeChar.compareTo(o.nodeChar);
}

代码示例来源:origin: huaban/jieba-analysis

/**
 * 实现Comparable接口
 * 
 * @param o
 * @return int
 */
public int compareTo(DictSegment o) {
  // 对当前节点存储的char进行比较
  return this.nodeChar.compareTo(o.nodeChar);
}

代码示例来源:origin: lealone/Lealone

@Override
public int compare(Object aObj, Object bObj) {
  Character a = (Character) aObj;
  Character b = (Character) bObj;
  return a.compareTo(b);
}

代码示例来源:origin: com.h2database/h2

@Override
public int compare(Object aObj, Object bObj) {
  if (aObj instanceof Character && bObj instanceof Character) {
    Character a = (Character) aObj;
    Character b = (Character) bObj;
    return a.compareTo(b);
  }
  return super.compare(aObj, bObj);
}

代码示例来源:origin: apache/avro

/**
  * Compares the characters of <code>o1</code> and <code>o2</code> at index <code>index</code>.
  *
  * @param o1 The left charsequence.
  * @param o2 The right charsequence.
  * @param index The zero-based index into the charsequences to compare.
  * @return a negative integer, zero, or a positive integer if the first argument is
  *     less than, equal to, or greater than the second, respectively.
  */
 private int compareCharacter(CharSequence o1, CharSequence o2, int index) {
  if (index < o1.length() && index < o2.length()) {
   return Character.valueOf(o1.charAt(index)).compareTo(Character.valueOf(o2.charAt(index)));
  }
  if (index >= o1.length() && index >= o2.length()) {
   return 0;
  }
  return o1.length() - o2.length();
 }
}

代码示例来源:origin: google/guava

public void testCompare() {
 for (char x : VALUES) {
  for (char y : VALUES) {
   // note: spec requires only that the sign is the same
   assertEquals(x + ", " + y, Character.valueOf(x).compareTo(y), Chars.compare(x, y));
  }
 }
}

代码示例来源:origin: alibaba/QLExpress

} else if (op1 instanceof Character || op2 instanceof Character) {
  if (op1 instanceof Character && op2 instanceof Character) {
    compareResult = ((Character) op1).compareTo((Character) op2);
  } else if (op1 instanceof Number) {
    compareResult = OperatorOfNumber.compareNumber((Number) op1, (int) ((Character) op2).charValue());

代码示例来源:origin: aol/cyclops

@Override
  public int compare(Character o1, Character o2) {
    return -o1.compareTo(o2);
  }
}).toString(),equalTo("wroolllhed "));

代码示例来源:origin: EugenePig/ik-analyzer-solr5

/**
 * 实现Comparable接口
 * @param o
 * @return int
 */
public int compareTo(DictSegment o) {
  //对当前节点存储的char进行比较
  return this.nodeChar.compareTo(o.nodeChar);
}

代码示例来源:origin: stackoverflow.com

Collections.sort(inList, new Comparator<Character>() {

  @Override
  public int compare(final Character o1, final Character o2) {
    int c = counts.get(o1).compareTo(counts.get(o2));
    if (c != 0) {
      return -c;
    }
    return o1.compareTo(o2);
  }
});

代码示例来源:origin: mlcsdev/mlcsseg

/**
 * 实现Comparable接口
 * @param o
 * @return int
 */
public int compareTo(DictSegment o) {
  //对当前节点存储的char进行比较
  return this.nodeChar.compareTo(o.nodeChar);
}

代码示例来源:origin: org.jboss.man/jboss-metatype

public int compare(Character o1, Character o2)
  {
   return o1.compareTo(o2);
  }
}

代码示例来源:origin: stackoverflow.com

String str = "Rohit";
 char[] charArray = str.toCharArray();
 Character[] myCharArr = ArrayUtils.toObject(charArray);
 Arrays.sort(myCharArr, new Comparator<Character>() {
   @Override
   public int compare(Character char1, Character char2) {
     return char2.compareTo(char1);
   }
 });
 for (char val: myCharArr) {
   System.out.print(val);
 }

代码示例来源:origin: stackoverflow.com

Arrays.sort(data, new Comparator<String[]>() {
  public int compare(String[] o1, String[] o2) {
    Character letter1 = o1[0].charAt(0);
    Character letter2 = o2[0].charAt(0);
    return letter1.compareTo(letter2);
  }
});

代码示例来源:origin: stackoverflow.com

Collections.sort(list, new Comparator<String>() {
 public int compare(String e1, String e2) {
  int c = new Character(e1.chartAt(0)).compareTo( e2.charAt(0) );
  if( c!=0 )
    return c;
  return new Character(e2.chartAt(e2.length()-1)).compareTo( e1.charAt(e1.length()-1) )
 }
});

代码示例来源:origin: stackoverflow.com

Collections.sort(l, new Comparator<Map.Entry<Character, Integer>>(){
      public int compare(Map.Entry<Character, Integer> o1, Map.Entry<Character, Integer> o2) {
       if (o1.getValue().equals(o2.getValue())){
         return -o1.getKey().compareTo(o2.getKey()))                          
       }
       else {
         return o1.getValue().compareTo(o2.getValue());
       }
     }});

代码示例来源:origin: com.h2database/h2-mvstore

@Override
public int compare(Object aObj, Object bObj) {
  if (aObj instanceof Character && bObj instanceof Character) {
    Character a = (Character) aObj;
    Character b = (Character) bObj;
    return a.compareTo(b);
  }
  return super.compare(aObj, bObj);
}

代码示例来源:origin: net.sf.uadetector/uadetector-core

@Override
  public int compareType(@Nonnull final Flag f1, @Nonnull final Flag f2) {
    final Character c1 = Character.valueOf(f1.getCharacter());
    final Character c2 = Character.valueOf(f2.getCharacter());
    return c1.compareTo(c2);
  }
}

代码示例来源:origin: com.googlecode.concurrent-trees/concurrent-trees

@Override
  public int compare(NodeCharacterProvider o1, NodeCharacterProvider o2) {
    return o1.getIncomingEdgeFirstCharacter().compareTo(o2.getIncomingEdgeFirstCharacter());
  }
}

代码示例来源:origin: org.onosproject/onlab-thirdparty

@Override
  public int compare(NodeCharacterProvider o1, NodeCharacterProvider o2) {
    return o1.getIncomingEdgeFirstCharacter().compareTo(o2.getIncomingEdgeFirstCharacter());
  }
}

相关文章

Character类方法