当我使用Collections.sort()时,它没有真正排序, 这是我的代码:
matchedWords.addAll(getIntent().getStringArrayListExtra("matched_words"));
TextView matchedTexts = findViewById(R.id.textView3);
matchedTexts.setMovementMethod(new ScrollingMovementMethod());
String text = "You have " + matchedWords.size() + " words in NewGsl Library";
matchedTexts.setText(text);
matchedTexts.append("\n");
Collections.sort(matchedWords);
for(String match : matchedWords)
{
matchedTexts.append( match.toLowerCase());
matchedTexts.append("\n");
}
结果是:
1.ıf
2.ıf
3.reading
4.a
5.a
6.about
.
.
.
答案 0 :(得分:2)
你可以这样做,
Collections.sort(matchedWords, new Comparator<String>() {
@Override
public int compare(String lhs, String rhs) {
return lhs.compareToIgnoreCase(rhs);
}
});