I was told that I should remove the last or third entry of the mapping, but I can't find any solution to these on how to get the specific entry and remove it.
Here is the code:
Scanner reader = new Scanner(System.in);
String input1, input2;
Map<String, String> students = new HashMap<>();
for(int i = 1; i <= 3; i++){
System.out.print("Enter student number " + i + ": ");
input1 = reader.next();
System.out.print("Enter first name " + i + ": ");
input2 = reader.next();
students.put(input1, input2);
}
System.out.println("Student List:");
for(Map.Entry entry: students.entrySet()){
System.out.println(entry.getKey() + " - " + entry.getValue());
}
I tried using the students.remove(students.get(3), students.get(3));
but still it doesn't work. Is there a possible solution to this? Please help.