private ArrayList<String> mArrayList = new ArrayList<String>();
mArrayList.clear();
mArrayList.add("test 3");
mArrayList.add("test 21");
mArrayList.add("test 4");
mArrayList.add("test 6");
mArrayList.add("test 1");
Collections.sort(mArrayList);
for (int i = 0; i < mArrayList.size(); i++) {
Log.e("TAG", "" + mArrayList.get(i));
}
결과는 다음과 같습니다Android에서 자연 정렬 순서로 ArrayList를 정렬 하시겠습니까?
test 1
test 21
test 3
test 4
test 6
하지만 내가 원하는 :
test 1
test 3
test 4
test 6
test 21
내가 그것을 분류되어 있지만 완벽하게, 그렇게하는 방법 모르겠어요, 당신이 어떤 생각을 가지고 있다면, 제발 나와 공유하십시오.
유형이 "자바 ArrayList를 사용자 정의 정렬 순서" –
은, Collections.sort (ArrayList에); 또는 비교기를 사용하십시오 – KOTIOS
이것을 ** 자연 정렬이라고합니다 **. –