Using Sets : Set « Utility Classes « SCJP






import java.util.HashSet;
import java.util.Set;

public class MainClass{
  public static void main(String[] args) {
    boolean[] ba = new boolean[5];
    // insert code here
    Set s = new HashSet();
    ba[0] = s.add("a");
    ba[1] = s.add(new Integer(42));
    ba[2] = s.add("b");
    ba[3] = s.add("a");
    ba[4] = s.add(new Object());
    
    for (int x = 0; x < ba.length; x++){
      System.out.print(ba[x] + " ");
    }
    
    System.out.println("\n");
    for (Object o : s){
      System.out.print(o + " ");
    }    
  }
}
true true true false true 

b a 42 java.lang.Object@3e25a5








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