I currently have an ordered list of String ids (List<String>
) and an unordered list of a custom class (List<CustomClass>
). I'd like to order the list of custom class objects based on the ordered list of IDS.
I got the impression the best way to do this is use a TreeMap. So I implemented this:
Map<String, CustomClass> mapB = new HashMap<String, CustomClass>();
for (String id : mIds) {
for (CustomClass customClass : mCustomClass) {
mapB.put(thingId, mCustomClass);
}
}
Map<String, CustomClass> treeMap = new TreeMap<String, CustomClass>();
treeMap.putAll(mapB);
Although, it stores all the ids fine, but when I print out the TreeMap, it seems as if it only takes the last Value of mapB and stores that. I.e. an example of logs:
Map: 1 : Paris, Map: 2 : Paris, Map: 3 : Paris
But what I added was:
mapB.put("1", London);
mapB.put("2", Berlin);
mapB.put("3", Paris);
So yeah, I'm a little confused to what's happening, could anyone provide some guidance? Thanks!