Java Reference
In-Depth Information
Thefollowingexampleshowsyouhowyoumightiterateoverthepreviousexample's
map entries:
for
(Map.Entry<String,
Color>
colorEntry:
color-
Map.entrySet())
System.out.println(colorEntry.getKey()+":
"+color-
Entry.getValue());
Whenrunningthisexampleagainstthepreviouslymentionedhashmapimplementa-
tion, 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
TreeMap
The TreeMap class provides a map implementation that is based on a red-black tree.
As a result, entries are stored in sorted order of their keys. However, accessing these
Search WWH ::




Custom Search