I am loading objects in an Java ArrayList from a SQL Query with an ORDER BY clause.
(1) Can I access that ArrayList with a foreach loop and get them back in
the order in which they were loaded?
(2) Similarly, can I consistently get the elements in the same SQL order by using get(n)? I.e. if the 3rd element in the SQL rowset was “x”, will get(2) always retrieve that?
Can I access that ArrayList with a foreach loop and get them back in the order in which they were loaded?Yes, List’s are ordered collection .
Similarly, can I consistently get the elements in the same SQL order by using get(n)? I.e. if the 3rd element in the SQL rowset was "x", will get(2) always retrieve that?Yes , As i said they are ordered , in the order they are inserted they can be retrieved in the same order.
Results: