Specifications
Sun Services
Java™ Programming Language
Module 9, slide 27 of 37
Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision F
A Set Example
1 import java.util.*;
2
3 public class SetExample {
4 public static void main(String[] args) {
5 Set set = new HashSet();
6 set.add("one");
7 set.add("second");
8 set.add("3rd");
9 set.add(new Integer(4));
10 set.add(new Float(5.0F));
11 set.add("second"); // duplicate, not added
12 set.add(new Integer(4)); // duplicate, not added
13 System.out.println(set);
14 }
15 }
The output generated from this program is:
[one, second, 5.0, 3rd, 4]










