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<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);
    //Object obj = Collections.min(hashSet);
    System.out.println(obj);//from w w w. j  a  va 2  s  . c  o  m
}

From source file:Main.java

public static void main(String[] argv) {
    Set<File> all = new HashSet<File>();
    getAllFileAndFolder(new File("c:\\"), all);
}

From source file:Main.java

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

    // populate hash set
    newset.add("Learning");
    newset.add("from");
    newset.add("java2s.com");

    // create an iterator
    Iterator iterator = newset.iterator();

    // check values
    while (iterator.hasNext()) {
        System.out.println("Value: " + iterator.next() + " ");
    }/*w ww  . jav  a  2s .co  m*/
}

From source file:MainClass.java

public static void main(String[] a) {
    Set s = new HashSet();
    s.add("A");//  w  w w.j av  a 2 s.  c  om
    s.add("B");
    s.add("C");
    s.add("D");
    s.add("E");
    s.add("F");
    s.add("H");
    Collections.synchronizedSet(s);
}

From source file:Main.java

public static void main(String[] args) {

    Set<String> s1 = new HashSet<>();

    // Add a few elements
    s1.add("HTML");
    s1.add("CSS");
    s1.add("XML");
    s1.add("XML"); // Duplicate

    // Create another set by copying s1
    Set<String> s2 = new HashSet<>(s1);
    // Add a few more elements 
    s2.add("Java");
    s2.add("SQL");
    s2.add(null); // one null is fine
    s2.add(null); // Duplicate

    System.out.println("s1: " + s1);
    System.out.println("s1.size(): " + s1.size());

    System.out.println("s2: " + s2);
    System.out.println("s2.size(): " + s2.size());
}

From source file:MainClass.java

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

    hs.add("B");/*from   w w  w.jav  a 2s  . c  o  m*/
    hs.add("A");
    hs.add("D");
    hs.add("E");
    hs.add("C");
    hs.add("F");

    System.out.println(hs);
}

From source file:MainClass.java

public static void main(String[] a) {
    Set s = new HashSet();
    s.add("A");//from   ww w . j a v a  2  s .  c o m
    s.add("B");
    s.add("C");
    s.add("D");
    s.add("E");
    s.add("F");
    s.add("H");

    Collections.unmodifiableSet(s);

    s = Collections.unmodifiableSet(s);

    s.clear();
}

From source file:Main.java

public static void main(String[] args) {
    Set<String> names = new HashSet<>();
    names.add("XML");
    names.add("Java");

    Stream<String> sequentialStream = names.stream();
    sequentialStream.forEach(System.out::println);

    Stream<String> parallelStream = names.parallelStream();
    parallelStream.forEach(System.out::println);
}

From source file:Main.java

public static void main(String args[]) {
    // create two hash sets      
    HashSet<String> cloneset = new HashSet<String>();

    HashSet<String> newset = new HashSet<String>();

    // populate hash set
    newset.add("Learning");
    newset.add("from");
    newset.add("java2s.com");

    // clone the hash set
    cloneset = (HashSet) newset.clone();

    System.out.println("Hash set values: " + newset);
    System.out.println("Clone Hash set values: " + cloneset);
}

From source file:Main.java

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

    // For a set or list
    for (Iterator it = collection.iterator(); it.hasNext();) {
        Object element = it.next();
    }/*from   www. ja v  a 2  s  . c o m*/
}