Method Description

boolean equals(Object o) Compare o with this entry for equality. Return true when o is also a map entry and the two entries have the same key and value.

Return this entry's key. This method optionally throws IllegalStateException when this entry has previously been removed from the backing map.

Return this entry's value. This method optionally throws IllegalStateException when this entry has previously been removed from the backing map.

Return this entry's hash code.

K getKey()

V getValue()

int hashCode()

Method Description

V setValue(V value) Replace this entry's value with value. The backing map is updated with the new value. This method throws UnsupportedOperationException when setValue() is not supported, ClassCastException when value's class prevents it from being stored in the backing map, NullPointerException when value contains the null reference and the backing map does not permit null, IllegalArgumentException when some property of value prevents it from being stored in the backing map, and (optionally) IllegalStateException when this entry has previously been removed from the backing map.

Method Description

V setValue(V value) Replace this entry's value with value. The backing map is updated with the new value. This method throws UnsupportedOperationException when setValue() is not supported, ClassCastException when value's class prevents it from being stored in the backing map, NullPointerException when value contains the null reference and the backing map does not permit null, IllegalArgumentException when some property of value prevents it from being stored in the backing map, and (optionally) IllegalStateException when this entry has previously been removed from the backing map.

Continuing from the previous example, Listing 8-22 shows you how you might iterate over the map's entries.

Listing 8-22. Iterating over a map's entries for (Map.Entry<String, Color> colorEntry: colorMap.entrySet())

System.out.println(colorEntry.getKey() + ": " + colorEntry.getValue());

When running Listing 8-22's code fragment against the previously mentioned hashmap implementation, you would observe the following output:

red: r = 255, g = 0, b = 0 blue: r = 0, g = 0, b = 255 green: r = 0, g = 255, b = 0 RED: r = 255, g = 0, b = 0

Was this article helpful?

0 0

Post a comment