import java.util.IdentityHashMap; 
import java.util.Map.Entry; 
import java.util.Set; 

public class MapTest {
	public static void main(String[] args) { 
		IdentityHashMap<String, String> identityHashMap = new IdentityHashMap<>(); 
		final String key = "key"; 
		final String oldValue = "oldValue"; 
		final String newValue = "newValue"; 

		identityHashMap.put(key, oldValue); 
		Set<Entry<String, String>> entrySet = identityHashMap.entrySet(); 

		@SuppressWarnings("unchecked") 
		Entry<String, String> arrayEntry = (Entry<String, String>) entrySet.toArray()[0]; 
		// Expecting that this changes value in map 
		arrayEntry.setValue(newValue); 
		// -> !! Did not change value 
		System.out.println("Expecting true: " + (identityHashMap.get(key) == newValue)); 

		Entry<String, String> iteratorEntry = entrySet.iterator().next(); 
		// Expecting that this changes value in map 
		iteratorEntry.setValue(newValue); 
		// -> Changed value 
		System.out.println("Expecting true: " + (identityHashMap.get(key) == newValue)); 

		/* 
		 * Set.toArray() contract is violated because here it does not return 
		 * "all of the elements in this set", it actually returns different elements 
		 */ 
	} 
}
