Update Behaviour of HashMap and HashSet with duplicate elements