javaandroid 对列表进行首字母排序和过滤相同字符串

xiaoxiao2025-08-10  25

List<String> topicNames = new ArrayList<>(new HashSet<>(topicName)); if (!topicNames.isEmpty()) { //不为空 Collections.sort(topicNames, new Comparator<String>() { @Override public int compare(String str1, String str2) { //根据文本排序 return str1.compareTo(str2); } }); }

结果是:英文名称的文件排序正常,中文名称的排序并没有按照首字母顺序。

另一个方法:

Comparator cmp= Collator.getInstance(Locale.CHINA);

Collections.sort(mFilename1,cmp);

过滤相同字符串:

List<String> topicNames = new ArrayList<>(new HashSet<>(topicName));

添加new HashSet();

转载请注明原文地址: https://www.6miu.com/read-5034601.html

最新回复(0)