Returning a boolean for such a thing as adding can be quite useful. In fact, put returns the old value since it uses it.
Therefore, you do not need to use get - or better containsKey , but you can:
public boolean add(RegistrationPlate plate, String owner) { String oldValue = register.put(plate, owner); return oldValue == null || !owner.equals(oldValue); }
|| ... || ... little bust.
source share