Java Reference
In-Depth Information
51 System.out.print( Ð{ Ñ );
52 for (String element : s)
53 {
54 System.out.print(element);
55 System.out.print( Ð Ñ );
56 }
57 System.out.println( Ð}Ñ );
58 }
59 }
703
704
Output
Add name, Q when done: Dick
{ Dick }
Add name, Q when done: Tom
{ Tom Dick }
Add name, Q when done: Harry
{ Harry Tom Dick }
Add name, Q when done: Tom
{ Harry Tom Dick }
Add name, Q when done: Q
Remove name, Q when done: Tom
{ Harry Dick }
Remove name, Q when done: Jerry
{ Harry Dick }
Remove name, Q when done: Q
S ELF C HECK
1. Arrays and lists remember the order in which you added elements; sets
do not. Why would you want to use a set instead of an array or list?
2. Why are set iterators different from list iterators?
Q UALITY T IP 16.1 Use Interface References to
Manipulate Data Structures
It is considered good style to store a reference to a HashSet or TreeSet in a
variable of type Set .
Set <String> names = new HashSet <String>();
Search WWH ::




Custom Search