an ArrayList does not guarantee order.
This is just wrong. An ArrayList
does guarantee order. It has a get(int index)
method which can be used to retrieve an element from the specified 0-based index. The add(T item)
method will add them in sequence to the list. You may be confusing the List collection type with the Set interface, which is similar to a List except for it does not guarantee order.
That said, it does not actually answer your question...
The ResultSet
, without a specified ordering, will return the data in the table's natural order. This is usually based of of the PK field(s) but this is not true for all DBMSs.
If order is important, specify it to be certain. Even if it comes back in the desired order now, changes to the DB schema might affect this later and break assumptions made by your code. Being explicit is better, and will express the code's intent clearer.
Update from edit to question:
If an order by is specified in the query, you can rely 100% on the order of the result set. No need to sort it again.