Tag: 连字符

Java不区分大小写的本地化排序

我有一组带连字符的字符串集。 考虑到语言环境,我想排序。 List words = Arrays.asList(“App – Small”, “Apple”, “App – Big”); Collator collator = Collator.getInstance(new Locale(“en”)); // Sort Method 1 Collections.sort(words, String.CASE_INSENSITIVE_ORDER); System.out.println(words.toString()); // Sort Method 2 collator.setStrength(Collator.PRIMARY); Collections.sort(words, collator); System.out.println(words.toString()); 结果 String.CASE_INSENSITIVE_ORDER [App – Big, App – Small, Apple] Collator.PRIMARY [App – Big, Apple, App – Small] 虽然Collat​​or.PRIMARY应该进行不区分大小写的排序,但使用上述两种方法的顺序之间存在差异。 如何实现与连字符一起使用的基于区域设置的不区分大小写的排序顺序。 [App – Big,App – […]