I will try to be as clear as possible.
I have N object lists. Each object stores an identifier field and a value field.
LIST A | ID1 v1 | ID2 v2 | ID3 v3 |
LIST B | ID1 v1' | ID2 v2' | ID3 v3' |
LIST C | ID1 v1''| ID2 v2''| ID3 v3''|
I need to create a hash map
Map<Integer,List<Double>>
like this:
------------------------
| ID1 | v1 v1' v1'' |
| ID2 | v2 v2' v2'' |
| ID3 | v3 v3' v3'' |
------------------------
For each list, I use this code as follows:
object_list.forEach( v -> {
String id = v.getID();
Double value = v.getValue();
if(map.containsKey(id)){
map.get(id).add(value);
}
else{
List<Double> list = new ArrayList<>();
list.add(value);
map.put(id, list);
}
});
My question is: can I complete this operation faster?
thank
source
share