For each student , there is a name , subject list along with marks . i need to take input for student name and his marks and then return the top 3 students based on marks. I tried using Hashmap and a list to get the marks. After taking the marks of 1st student in list i am clearing everything from the list and taking the input again. But this is changing the data for the first student also . I am not sure what i am doing wrong here?
HashMap<String,ArrayList<Integer>> map=new HashMap<>();
ArrayList<Integer> marks=new ArrayList<>();
//1st student detail
marks.add(12);
marks.add(10);
marks.add(15);
map.put("Rakesh",marks);
System.out.println(map);
//Reset the marks List
marks.clear();
//2nd student detail
marks.add(9);
marks.add(8);
marks.add(15);
map.put("Ashwin",marks);
System.out.println(map);
//Reset the marks List
marks.clear()
//3rd student detail
marks.add(7);
marks.add(11);
marks.add(8);
map.put("Rahul",marks);
System.out.println(map);```