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() 

Source Link

Document

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

Usage

From source file:Main.java

public static void main(String[] args) {
    HashSet<Integer> hSet = new HashSet<Integer>();

    hSet.add(new Integer("1"));
    hSet.add(new Integer("2"));
    hSet.add(new Integer("3"));

    System.out.println(hSet);//from  w ww  .ja v  a  2 s.  c  o m

    boolean blnRemoved = hSet.remove(new Integer("2"));

    System.out.println(blnRemoved);

    System.out.println(hSet);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Set set1 = new HashSet();
    Set set2 = new HashSet();

    set1.addAll(set2);/*from ww w .  j  a v a2 s  .  c  o m*/

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Set set1 = new HashSet();
    Set set2 = new HashSet();

    set1.retainAll(set2);/*from   ww w .  j av  a  2 s. c  o  m*/

    // Remove all elements from a set
    set1.clear();

}

From source file:FindDups2.java

public static void main(String[] args) {
    Set<String> uniques = new HashSet<String>();
    Set<String> dups = new HashSet<String>();

    for (String a : args)
        if (!uniques.add(a))
            dups.add(a);//from w  w  w  .  j ava  2 s .c o  m

    uniques.removeAll(dups);

    System.out.println("Unique words:    " + uniques);
    System.out.println("Duplicate words: " + dups);
}

From source file:FindDupsAndUnique.java

public static void main(String args[]) {
    Set uniques = new HashSet();
    Set dups = new HashSet();
    String[] values = new String[] { "java", "java2", "java2s", "javas", "java" };
    for (int i = 0; i < values.length; i++)
        if (!uniques.add(values[i]))
            dups.add(values[i]);//  w w  w.ja  v  a  2  s.com

    uniques.removeAll(dups); // Destructive set-difference

    System.out.println("Unique words:    " + uniques);
    System.out.println("Duplicate words: " + dups);
}

From source file:Main.java

public static void main(String[] args) {
    HashSet<Long> hashSet = new HashSet<Long>();

    hashSet.add(new Long("9"));
    hashSet.add(new Long("4"));
    hashSet.add(new Long("2"));
    hashSet.add(new Long("2"));
    hashSet.add(new Long("3"));

    Object obj = Collections.min(hashSet);
    System.out.println("Minimum Element of Java HashSet is : " + obj);
}

From source file:Main.java

public static void main(String[] args) {
    HashSet<Long> hashSet = new HashSet<Long>();

    hashSet.add(new Long("9"));
    hashSet.add(new Long("4"));
    hashSet.add(new Long("2"));
    hashSet.add(new Long("2"));
    hashSet.add(new Long("3"));

    Object obj = Collections.min(hashSet);
    System.out.println("Minimum Element of HashSet is : " + obj);
}

From source file:Main.java

public static void main(String[] args) {
    HashSet<Long> hashSet = new HashSet<Long>();
    hashSet.add(new Long("1111111111"));
    hashSet.add(new Long("2222222222"));
    hashSet.add(new Long("3333333333"));
    hashSet.add(new Long("4444444444"));
    hashSet.add(new Long("5555555555"));

    Object obj = Collections.max(hashSet);
    System.out.println(obj);/* w  ww.  j av  a 2  s.c  om*/
}

From source file:Main.java

public static void main(String[] args) {
    HashSet hashSet = new HashSet();
    Set set = Collections.synchronizedSet(hashSet);
}

From source file:Main.java

public static void main(String[] args) {

    HashSet<Integer> hSet = new HashSet<Integer>();

    hSet.add(new Integer("1"));
    hSet.add(new Integer("2"));
    hSet.add(new Integer("3"));

    Iterator itr = hSet.iterator();

    while (itr.hasNext())
        System.out.println(itr.next());
}