0

I am looking to implement a sort feature. I want to sort the files in File[] list in a custom format.

File newfile = new File("reports/Weekly/xyz");
File[] list = newfile.listFiles();
Arrays.sort(list, NameFileComparator.NAME_COMPARATOR);

The files appear in the following sequence based on the above code:

1. reports/Weekly/xyz/cmp.xlsx
2. reports/Weekly/xyz/bn-wk.xlsx
3. reports/Weekly/xyz/se-wk.xlsx
4. reports/Weekly/xyz/se-wk-yoy.xlsx 

But i want it in a custom order. Meaning,

1. reports/Weekly/xyz/se-wk.xlsx
2. reports/Weekly/xyz/se-wk-yoy.xlsx 
3. reports/Weekly/xyz/bn-wk.xlsx
4. reports/Weekly/xyz/cmp.xlsx

How can I write a custom sort function to do this?

nidhi
  • 299
  • 3
  • 4
  • 21

0 Answers0