java.text.Collator.compare()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(213)

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

Collator.compare介绍

[英]Compares two objects to determine their relative order. The objects must be strings.
[中]比较两个对象以确定其相对顺序。对象必须是字符串。

代码示例

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

private int compare(String o1, String o2) {
  return Collator.getInstance().compare(o1, o2);
}

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

LinkedList<String> list = new LinkedList<String>();
  list.add("abc");
  list.add("Bcd");
  list.add("aAb");
  Collections.sort(list, new Comparator<String>() {
    @Override
    public int compare(String o1, String o2) {
      return Collator.getInstance().compare(o1, o2);
    }
  });

代码示例来源:origin: aws/aws-sdk-java

/**
 * Compare two strings with Locale.ENGLISH
 * This method is preferred over String.compareTo() method.
 * @param str1 String 1
 * @param str2 String 2
 * @return negative integer if str1 lexicographically precedes str2
 *            positive integer if str1 lexicographically follows str2
 *             0 if both strings are equal
 * @throws IllegalArgumentException throws exception if both or either of the strings is null
 */
public static int compare(String str1, String str2) {
  if( str1 == null || str2 == null) {
    throw new IllegalArgumentException("Arguments cannot be null");
  }
  Collator collator = Collator.getInstance(LOCALE_ENGLISH);
  return collator.compare(str1, str2);
}

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

@Override
  public int compare(final Class class1, final Class class2) {
    return Collator.getInstance(Locale.US).compare(class1.getSimpleName(), class2.getSimpleName());
  }
};

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

public int compare(String arg1, Sting arg2) {
  Collator usCollator = Collator.getInstance(Locale.US); //Your locale here
  usCollator.setStrength(Collator.PRIMARY);
  return usCollator.compare(arg1, arg2);
}

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

import java.text.Collator;
import java.util.Locale;

public class CollatorExp {

  public static void main(String[] args) {
    Collator collator = Collator.getInstance(Locale.FRENCH);
    collator.setStrength(Collator.PRIMARY);

    if (collator.compare("débárquér", "debarquer") == 0) {
      System.out.println("Both Strings are equal");
    } else {
      System.out.println("Both Strings are not equal");
    }
  } 
}

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

@Override
  public int compare(final PropertyDescriptor o1, final PropertyDescriptor o2) {
    return Collator.getInstance(Locale.US).compare(o1.getName(), o2.getName());
  }
});

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

@Override
  public int compare(final PropertyDescriptor o1, final PropertyDescriptor o2) {
    return Collator.getInstance(Locale.US).compare(o1.getName(), o2.getName());
  }
});

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

@Override
  public int compare(final PropertyDescriptor o1, final PropertyDescriptor o2) {
    return Collator.getInstance(Locale.US).compare(o1.getName(), o2.getName());
  }
});

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

@Override
  public int compare(AttributeDTO a1, AttributeDTO a2) {
    return Collator.getInstance(Locale.US).compare(a1.getName(), a2.getName());
  }
};

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

@Override
  public int compare(final RelationshipDTO r1, final RelationshipDTO r2) {
    return Collator.getInstance(Locale.US).compare(r1.getName(), r2.getName());
  }
});

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

@Override
  public int compare(final PropertyDescriptor o1, final PropertyDescriptor o2) {
    return Collator.getInstance(Locale.US).compare(o1.getName(), o2.getName());
  }
});

代码示例来源:origin: GlowstoneMC/Glowstone

Collator caseInsensitive = Collator.getInstance(messages.getLocale());
caseInsensitive.setStrength(Collator.PRIMARY);
if (caseInsensitive.compare(args[0], "ips") == 0) { // NON-NLS
  banType = BanList.Type.IP;
} else if (caseInsensitive.compare(args[0], "players") == 0) { // NON-NLS
  banType = BanList.Type.NAME;
} else {

代码示例来源:origin: siacs/Conversations

final Collator collator = Collator.getInstance();
int result;
  result = o.getDomain() != null ? collator.compare(getDomain(), o.getDomain()) : -1;
} else {
  result = o.getDomain() != null ? 1 : 0;
  if (getLocal() != null) {
    result = o.getLocal() != null ? collator.compare(getLocal(), o.getLocal()) : 1;
  } else {
  if (getResource() != null) {
    return o.getResource() != null ? collator.compare(getResource(), o.getResource()) : 1;
  } else {

代码示例来源:origin: com.alibaba/druid

private int compare(String o1, String o2) {
  return Collator.getInstance().compare(o1, o2);
}

代码示例来源:origin: i2p/i2p.i2p

public static int comp(FileAndIndex l, FileAndIndex r) {
    boolean ld = l.isDirectory;
    boolean rd = r.isDirectory;
    if (ld && !rd)
      return -1;
    if (rd && !ld)
      return 1;
    return Collator.getInstance().compare(l.file.getName(), r.file.getName());
  }
}

代码示例来源:origin: ahmetaa/zemberek-nlp

public static Comparator<File> getNameSortingComparator(final Locale locale) {
 return (file, file1) -> {
  Collator coll = Collator.getInstance(locale);
  return coll.compare(file.getName(), file1.getName());
 };
}

代码示例来源:origin: ahmetaa/zemberek-nlp

public static Comparator<File> getAbsolutePathSortingComparator(final Locale locale) {
 return (file, file1) -> {
  Collator coll = Collator.getInstance(locale);
  return coll.compare(file.getAbsolutePath(), file1.getAbsolutePath());
 };
}

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

Collator deCollator = Collator.getInstance(Locale.GERMANY); // or new Locale("pl", "PL") for polish locale ;)
System.out.println(deCollator.compare("abcö", "abco"));

代码示例来源:origin: com.amazonaws/aws-java-sdk-core

/**
 * Compare two strings with Locale.ENGLISH
 * This method is preferred over String.compareTo() method.
 * @param str1 String 1
 * @param str2 String 2
 * @return negative integer if str1 lexicographically precedes str2
 *            positive integer if str1 lexicographically follows str2
 *             0 if both strings are equal
 * @throws IllegalArgumentException throws exception if both or either of the strings is null
 */
public static int compare(String str1, String str2) {
  if( str1 == null || str2 == null) {
    throw new IllegalArgumentException("Arguments cannot be null");
  }
  Collator collator = Collator.getInstance(LOCALE_ENGLISH);
  return collator.compare(str1, str2);
}

相关文章