For the Java app I am currently developing I am using an ID system, each ID being a unique string. I have two array lists, one is a an ArrayList<String> which holds just the IDs in the correct order, the other is an array list of objects which all have an .ID field. What is the best way to order the array list of objects so that their IDs are in the same order as the array list of String IDs?
For the Java app I am currently developing I am using an ID system,
Share
I’d put all objects in a HashMap using their ID as key, then run over second ID list and create new list of objects using ID and map. Should have a complexity around 2n -> n while not as resource friendly.
EDIT: to make it clear what I mean
Assuming objectList and idList have the same size and same ids/object.IDs resp.