I have the following array
I am trying to save the array information in a hashmap.
String[][] students = {{"Bobby", 87}, {"Charles", 100}, {"Eric", 64},
{"Charles", 22}};
Map<String, List<Integer>> map = new HashMap<>();
List<Integer> score1 = new ArrayList<>();
for(int i=0; i<students.length; i++) {
score1.add(students[i][1]);
map.put(students[i][0], score1);
}
But i want to store the information in the map key value pair.
Expected output:
"Bobby" -> 87
"Charles" -> 100,22
"Eric" -> 64
Actual output:
{Charles=[87, 100, 64, 22], Eric=[87, 100, 64, 22], Bobby=[87, 100, 64, 22]}
how can I do this?