It's because the way how java compares strings by default in java (lexicographic order).
You can define your own comparator for File
objects and sort.
java.io.File.list() giving different order as the folders created sequentially [duplicate]
-
01-10-2022 - |
Question
java.io.File.list() giving different order as the folders created sequentially
While creating the Temporary folders with name as
"Temp" + auto-incremented number
e.g. Temp1, Temp2, Temp3...Temp10, Temp11 and so on.
But when I use java.io.File.list() to get the folder list to further processing in order as the folder created,
but its giving as Temp1, Temp10, Temp11...Temp19, Temp2, Temp20, Temp21 and so on.
I also tried Arrays.sort(files); but no change in order of folder list
Please tell how to get the same order list as the folders created sequentially?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow