Sets may not contain duplicate elements. : Set « Utility Classes « SCJP






import java.awt.Point;
import java.util.HashSet;
import java.util.Set;

public class MainClass {
  public static void main(String[] argv) {
    Set set = new HashSet();
    set.clear();
    Point p1 = new Point(10, 20);
    Point p2 = new Point(10, 20);
    set.add(p1);
    set.add(p2);
    System.out.println(set.size());

  }
}
1








8.16.Set
8.16.1.Sets may not contain duplicate elements.
8.16.2.An Iterator from HashSet presents elements in an unpredictable random order.
8.16.3.Sets differ from lists in that they are unordered and cannot contain duplicates of the same element.
8.16.4.Using Sets