Java Reference
In-Depth Information
Display 15.37
Set<T>
Class
(part 4 of 4)
98
interSet.add(position.data);
99
position = position.link;
100
}
101
return
interSet;
The
clear
,
size
, and
isEmpty
methods are identical
to those in Display 15.8 for the
LinkedList3
class.
102
}
103
}
Display 15.38
Set Class Demo
(part 1 of 2)
1
class
SetDemo
2{
3
public
class
static
void
main(String[] args)
4
{
5
// Round things
6
Set round =
new
Set<String>( );
7
// Green things
8
Set green =
new
Set<String>( );
9
// Add some data to both sets
10
round.add("peas");
11
round.add("ball");
12
round.add("pie");
13
round.add("grapes");
14
green.add("peas");
15
green.add("grapes");
16
green.add("garden hose");
17
green.add("grass");
18
System.out.println("Contents of set round: ");
19
round.output( );
20
System.out.println("Contents of set green: ");
21
green.output( );
22
System.out.println( );
23
System.out.println("ball in set round? " +
24
round.contains("ball"));
25
System.out.println("ball in set green? " +
26
green.contains("ball"));
(continued)