hashmap key includes registration number and hashmap value includes owners name. Here is my code:
public static void main(String[] args) {
HashMap<String, String> data = new HashMap<>();
Scanner reader = new Scanner(System.in);
data.put("AAA-111", "Jack");
data.put("BBB-222", "Matt");
data.put("CCC-333", "Jack");
for (HashMap.Entry<String, String> entry: data.entrySet()) {
System.out.println(entry.getValue());
//data.values().remove(entry.getValue());
}
}
And the current output:
Jack
Matt
Jack
The problem is that I don't want to print out same owner two times. My goal output is:
Jack
Matt
How I can print same values only one time?