I have one arraylist and one String array. The String array contains identifiers, and the list of arrays contains identifiers and information associated with these identifiers. This ArrayList is in an undesirable order. I have String Array identifiers in the order I want them to be in an ArrayList.
An example of semi-pseudo-code:
ArrayList<MyObject> myList = new ArrayList<MyObject>(); for (every username) { myList.add(new MyObject(id, username, content, country); } String[] ids = new String[myList.size()]; ...Ids are added and sorted here...
Now I have a list of identifiers in the correct order. Each Id in "myList" corresponds to an identifier in the String "ids" array. I want to sort "myList" based on its corresponding identifier in the "ids" string array.
How can I re-sort my ArrayList this way?
Eg. if in Array list I have: 1. 123, Bob, test, USA 2. 1234, Vladimir, test, USA 3. 12345, Yoseph, test, USA and in the String[] I have: 1. 1234 2. 123 3.12345
How can I reorder an ArrayList based on identifiers in an array of strings by creating:
1. 1234, Vladimir, test, USA 2. 123, Bob, test, USA 3. 12345, Yoseph, test, USA