Example usage for java.util HashSet HashSet

List of usage examples for java.util HashSet HashSet

Introduction

In this page you can find the example usage for java.util HashSet HashSet.

Prototype

public HashSet(int initialCapacity) 

Source Link

Document

Constructs a new, empty set; the backing HashMap instance has the specified initial capacity and default load factor (0.75).

Usage

From source file:Main.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    Set<String> set = new HashSet<String>(Arrays.asList(elements));

    Object[] arrObj = set.toArray();

    for (int i = 0; i < arrObj.length; i++) {
        System.out.println(arrObj[i]);
    }/*from   w ww  .j  a v a 2 s  .  c  o m*/

    System.out.println(set);
}

From source file:MainClass.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    Set set = new HashSet(Arrays.asList(elements));

    String[] strObj = new String[set.size()];

    strObj = (String[]) set.toArray(strObj);

    for (int i = 0; i < strObj.length; i++) {
        System.out.println(strObj[i]);
    }/*from ww w.j  av a  2 s. c o m*/

    System.out.println(set);
}

From source file:MainClass.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    Set set = new HashSet(Arrays.asList(elements));

    elements = new String[] { "E", "F" };

    set.addAll(Arrays.asList(elements));

    System.out.println(set);//from   ww  w. j  a  v a  2 s.  co m

    set.clear();

    System.out.println(set);
}

From source file:Main.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    HashSet<String> set = new HashSet<String>(Arrays.asList(elements));

    Object[] arrObj = set.toArray();

    for (int i = 0; i < arrObj.length; i++) {
        System.out.println(arrObj[i]);
    }//from www.  ja  v a2  s .  c om

    System.out.println(set);
}

From source file:Main.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    Set<String> set = new HashSet<String>(Arrays.asList(elements));

    elements = new String[] { "E", "F" };

    set.addAll(Arrays.asList(elements));

    System.out.println(set);/*from   ww  w.j  a  v a2 s  .c  o  m*/

    set.clear();

    System.out.println(set);
}

From source file:Main.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    HashSet<String> set = new HashSet<String>(Arrays.asList(elements));

    elements = new String[] { "E", "F" };

    set.addAll(Arrays.asList(elements));

    System.out.println(set);/*  w ww.  j  a  v a2 s.  co  m*/

    set.clear();

    System.out.println(set);
}

From source file:Main.java

public static void main(String args[]) {
    String elements[] = { "I", "P", "E", "G", "P" };
    Set set = new HashSet(Arrays.asList(elements));
    Iterator iter = set.iterator();
    while (iter.hasNext()) {
        System.out.println(iter.next());
    }/*from  ww  w.  j  a v  a  2  s . c om*/
}

From source file:MainClass.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    Set set = new HashSet(Arrays.asList(elements));

    Iterator iter = set.iterator();
    while (iter.hasNext()) {
        System.out.println(iter.next());
    }/*from  w  ww. j a v  a2s.c om*/

}

From source file:Copy.java

public static void main(String args[]) throws Exception {
    String elements[] = { "Irish Setter", "Poodle", "English Setter", "Gordon Setter", "Pug" };
    Set set = new HashSet(Arrays.asList(elements));
    Set set2 = ((Set) ((HashSet) set).clone());
    System.out.println(set2);//from   w ww  .ja  v a 2 s. co  m
    FileOutputStream fos = new FileOutputStream("set.ser");
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    oos.writeObject(set);
    oos.close();
    FileInputStream fis = new FileInputStream("set.ser");
    ObjectInputStream ois = new ObjectInputStream(fis);
    Set set3 = (Set) ois.readObject();
    ois.close();
    System.out.println(set3);
}

From source file:Main.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    HashSet<String> set = new HashSet<String>(Arrays.asList(elements));

    Iterator iter = set.iterator();
    while (iter.hasNext()) {
        System.out.println(iter.next());
    }/*w  w  w  .  ja  v a2  s .c  o  m*/

}