List of usage examples for java.util Set add
boolean add(E e);
From source file:MainClass.java
public static void main(String[] a) { Set s = new HashSet(); s.add("A"); s.add("B");//from w w w . j ava2 s .c o m s.add("C"); s.add("D"); s.add("E"); s.add("F"); s.add("H"); Collections.synchronizedSet(s); }
From source file:MainClass.java
public static void main(String[] a) { Set set = new HashSet(); set.add("Hello"); if (set.add("Hello")) { System.out.println("addition successful"); } else {//w w w .ja v a 2s. c om System.out.println("addition failed"); } }
From source file:MainClass.java
public static void main(String[] a) { Set s = new HashSet(); s.add("A"); s.add("B");//from w w w .j a va 2s .co m 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[] a) { Set<String> set = new HashSet<String>(); set.add("Hello"); if (set.add("Hello")) { System.out.println("addition successful"); } else {/*w w w . j a v a2 s.co m*/ System.out.println("addition failed"); } }
From source file:Main.java
public static void main(String[] args) { Set<String> s1 = new LinkedHashSet<>(); s1.add("A"); s1.add("B");/*ww w . j a v a 2s . c o m*/ s1.add("C"); s1.add("D"); System.out.println("LinkedHashSet: " + s1); }
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)); set.add("Z"); System.out.println(set);// www .j a v a2s . c o m }
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);/* w w w .j a v a 2 s . co m*/ System.out.println("Object = " + o); } }
From source file:Main.java
public static void main(String[] args) { Set<String> set = new TreeSet<String>(); set.add("Z"); set.add("A"); set.add("F"); set.add("B"); set.add("H"); set.add("X"); set.add("N"); for (String item : set) { System.out.print(item + " "); }/* www . j a va 2 s . c o m*/ }
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); Object[] objects = list.toArray(); for (int i = 0; i < objects.length; i++) { Object object = objects[i]; System.out.println("Object = " + object); }/*from w w w . j a va 2 s. com*/ }