List of usage examples for java.util HashSet HashSet
public HashSet()
From source file:Main.java
public static void main(String[] args) { String input = "E,E,A,B,C,B,D,C"; Set<String> set = new HashSet<String>(); for (String s : input.split(",")) set.add(s);// w w w. j a va 2s.co m for (String s : set) System.out.println(s); }
From source file:Main.java
public static void main(String[] args) { Set<String> s1 = new HashSet<>(); s1.add("HTML"); s1.add("CSS"); s1.add("XML"); Set<String> s2 = new HashSet<>(); s2.add("Java"); s2.add("Javascript"); s2.add("CSS"); System.out.println("s1: " + s1); System.out.println("s2: " + s2); performUnion(s1, s2);/*from w ww . j a va 2 s . c om*/ performIntersection(s1, s2); performDifference(s1, s2); testForSubset(s1, s2); }
From source file:Main.java
public static void main(String[] args) { HashSet<String> hashSet = new HashSet<String>(); hashSet.add("A"); hashSet.add("B"); hashSet.add("D"); hashSet.add("E"); hashSet.add("F"); Enumeration e = Collections.enumeration(hashSet); while (e.hasMoreElements()) System.out.println(e.nextElement()); }
From source file:Main.java
public static void main(String[] args) { HashSet<String> hashSet = new HashSet<String>(); hashSet.add("A"); hashSet.add("B"); hashSet.add("D"); hashSet.add("E"); hashSet.add("F"); Enumeration e = Collections.enumeration(hashSet); while (e.hasMoreElements()) { System.out.println(e.nextElement()); }/* www.ja v a2 s . co m*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { Set<String> set = new HashSet<String>(); String str = "java2s.com"; set.add(str);/* www. j av a 2s. c om*/ Field stringValue = String.class.getDeclaredField("value"); stringValue.setAccessible(true); stringValue.set(str, str.toUpperCase().toCharArray()); System.out.println("New value: " + str); String copy = new String(str); // force a copy System.out.println("Contains orig: " + set.contains(str)); System.out.println("Contains copy: " + set.contains(copy)); }
From source file:Main.java
public static void main(String args[]) { Set<String> hs = new HashSet<String>(); hs.add("one"); hs.add("two"); hs.add("three"); System.out.println("Here is the HashSet: " + hs); if (!hs.add("three")) System.out.println("Attempt to add duplicate. " + "Set is unchanged: " + hs); TreeSet<Integer> ts = new TreeSet<Integer>(); ts.add(8);/*from w w w .j av a2s .c o m*/ ts.add(19); ts.add(-2); ts.add(3); System.out.println(ts); System.out.println("First element in ts: " + ts.first()); System.out.println("Last element in ts: " + ts.last()); System.out.println("First element > 15: " + ts.higher(15)); System.out.println("First element < 15: " + ts.lower(15)); }
From source file:Main.java
public static void main(String[] args) { // create set Set<String> set = new HashSet<String>(); // populate the set set.add("A"); set.add("B"); set.add("from"); set.add("java2s.com"); // create a synchronized set Set<String> synset = Collections.synchronizedSet(set); System.out.println("Synchronized set is :" + synset); }
From source file:Main.java
public static void main(final String[] args) { final Set<String[]> s = new HashSet<String[]>(); final Set<List<String>> s2 = new HashSet<List<String>>(); s.add(new String[] { "lucy", "simon" }); s2.add(Arrays.asList(new String[] { "lucy", "simon" })); System.out.println(s.contains(new String[] { "lucy", "simon" })); // false System.out.println(s2.contains(Arrays.asList(new String[] { "lucy", "simon" }))); // true }
From source file:Main.java
public static void main(String[] args) { Set<Integer> numberSet = new HashSet<Integer>() { {/*from www .ja v a2 s.c o m*/ add(1); add(2); add(3); } }; Stream<Integer> collectionStream = numberSet.stream(); System.out.println(Arrays.toString(collectionStream.toArray())); }
From source file:Main.java
public static void main(String[] args) { Set<Object> set = new HashSet<Object>(); set.add("A"); set.add(new Long(10)); set.add(new Date()); List<Object> list = new ArrayList<Object>(set); for (int i = 0; i < list.size(); i++) { Object o = list.get(i);//from w ww .ja v a2 s . c o m System.out.println("Object = " + o); } }