Reputation: 45
Can anyone help me about how to sort array list of string containing paths. i used Collection.sort(my_list); but it didn't worked fine , it sorts them in order according to the folder names like suppose i have files :
mnt/sdcard/A.jpg
mnt/sdcard/folder1/B.jpg
mnt/sdcard/C.jpg
mnt/sdcard/folder2/D.jpg
after Collections.sort(my_list) :
mnt/sdcard/A.jpg
mnt/sdcard/c.jpg
mnt/sdcard/folder1/b.jpg
mnt/sdcard/folder2/d.jpg
i want results like :
mnt/sdcard/A.jpg
mnt/sdcard/folder1/B.jpg
mnt/sdcard/C.jpg
mnt/sdcard/folder2/D.jpg
Upvotes: 2
Views: 147
Reputation: 157437
String name = new File("mnt/sdcard/c.jpg").getName();
returns c.jpg
Use it for each String in your Collection
, in your comparator to sort the List
Upvotes: 1
Reputation: 2749
One way to do it is to get the substring of each string after the last "/". Then you can sort by that value.
String sub = myString.substring(string.lastIndexOf('/') + 1);
Upvotes: 0