I\'m trying to fix this piece of code where I\'m printing from a hashmap having a list of plate numbers and owners (that format). I\'m trying to print out just the owners
To remove the duplicates, use a HashSet<String>:
public void printOwners() {
for (String s : new HashSet<>(owners.values())) {
System.out.println(s);
}
}
Alternatively with Java 8 Stream
and the distinct()
method:
public void printOwners() {
owners.values().stream().distinct().forEach(System.out::println);
}