开发者

How to create a file list on Android with alphabetical case insensitive order?

At the moment I use this to create an array of directories and files in the directory /mnt/sdcard.

This sorts the filelist开发者_Python百科 in alphabetical order, but case sensitive.

I would like to have this case insensitive.

File f = new File("/mnt/sdcard/");
File[] files = f.listFiles();

Arrays.sort(files);


You can use File.isFile() to check which things are files. See: http://download.oracle.com/javase/1.4.2/docs/api/java/io/File.html

You can use the Arrays.sort() where you pass in a Comparator to make the comparison case insensitive. see: Arrays Documentation

You'll want to first split the array into 2 arrays, 1 for directories and 1 for files. Then do the sort on each array.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜