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: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[] { "B", "D", "F", "G", "1", "2", "3", "4" };
    Set set2 = new HashSet(Arrays.asList(elements));

    set.removeAll(set2);/*  ww  w.  j av a  2s  .c  om*/
    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);// w  w w .j ava2 s. c  o m
}

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[] { "A", "B", "C" };
    Set<String> set2 = new HashSet<String>(Arrays.asList(elements));

    System.out.println(set.containsAll(set2));
}

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[] { "A", "B", "C", "D" };
    Set<String> set2 = new HashSet<String>(Arrays.asList(elements));

    System.out.println(set.equals(set2));
}

From source file:Main.java

public static void main(String[] args) {
    String elements[] = { "M", "N", "O", "P", "Q" };
    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  w w  w .  ja  v  a2  s  .co  m
    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[] { "B", "D", "F", "G", "1", "2", "3", "4" };
    Set<String> set2 = new HashSet<String>(Arrays.asList(elements));

    set.removeAll(set2);/*from w  w  w . j  av  a 2 s  .  com*/
    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));

    HashSet set2 = ((Set) ((HashSet) set).clone());

    System.out.println(set2);/*ww w . j  av a  2s.c om*/
}

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[] { "A", "B", "C" };
    HashSet<String> set2 = new HashSet<String>(Arrays.asList(elements));

    System.out.println(set.containsAll(set2));
}

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[] { "B", "D", "F", "G", "1", "2", "3", "4" };
    HashSet<String> set2 = new HashSet<String>(Arrays.asList(elements));

    set.removeAll(set2);/*  w  w  w .j  a v  a  2  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" };
    HashSet<String> set = new HashSet<String>(Arrays.asList(elements));

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

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

    System.out.println(set);//from   w w  w .  j av  a2s  . co  m
}