Why does listFiles () not guarantee an order?

It seems strange to say.

There is no guarantee that name strings in the resulting array will appear in any particular order; they are not, in particular, guaranteed to appear in alphabetical order.

Why the order cannot be guaranteed? What happens when one ls can, for example, be reasonable by default.

Is it something that was decided for a reason (performance?), Or perhaps where is some deeper truth?

+4
source share
1 answer

As far as I know, there is no natural order that files tend to. If you speak alphabetic, then with what language / sort sequence? Do all operating systems supported by java do support in order? If not, then the API will have to use everything that was received from the OS. Since it is likely that the API client 1) may not bother you, or 2) wants something else, it is much more reasonable to simply deliver files without a guaranteed order, rather than doing empty sorting. If you do not care, you can do it.

+8
source

All Articles