List of usage examples for java.util Set add
boolean add(E e);
From source file:Comp.java
public static void main(String args[]) throws Exception { String elements[] = { "Irish Setter", "Poodle", "English Setter", "Gordon Setter", "Pug" }; Set set = new TreeSet(Collections.reverseOrder()); for (int i = 0, n = elements.length; i < n; i++) { set.add(elements[i]); }//from w w w .j a va 2s . c om System.out.println(set); System.out.println(((TreeSet) set).comparator()); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { String elements[] = { "A", "C", "D", "G", "F" }; Set set = new TreeSet(Collections.reverseOrder()); for (int i = 0, n = elements.length; i < n; i++) { set.add(elements[i]); }/*from ww w. java 2 s .c om*/ System.out.println(set); System.out.println(((TreeSet) set).comparator()); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { String elements[] = { "A", "C", "D", "G", "F" }; Set set = new TreeSet(Collections.reverseOrder()); for (int i = 0, n = elements.length; i < n; i++) { set.add(elements[i]); }/* ww w . j av a 2s . c om*/ System.out.println(set); }
From source file:MainClass.java
public static void main(String args[]) { String[] name1 = { "Amy", "Jose", "Jeremy", "Alice", "Patrick" }; String[] name2 = { "Alan", "Amy", "Jeremy", "Helen", "Alexi" }; String[] name3 = { "Adel", "Aaron", "Amy", "James", "Alice" }; Set<String> letter = new HashSet<String>(); for (int i = 0; i < name1.length; i++) letter.add(name1[i]); for (int j = 0; j < name2.length; j++) letter.add(name2[j]);//from www. ja v a 2 s .co m for (int k = 0; k < name3.length; k++) letter.add(name3[k]); System.out.println(letter.size() + " letters must be sent to: " + letter); }
From source file:SetDemo.java
public static void main(String[] args) { String[] letters = { "A", "B", "C", "D", "E" }; Set s = new HashSet(); for (int i = 0; i < letters.length; i++) s.add(letters[i]); if (!s.add(letters[0])) System.out.println("Cannot add a duplicate.\n"); Iterator iter = s.iterator(); while (iter.hasNext()) System.out.println(iter.next()); System.out.println(""); SortedSet ss = new TreeSet(); for (int i = 0; i < letters.length; i++) ss.add(letters[i]);/*from w ww.ja v a 2 s. c o m*/ if (!ss.add(letters[0])) System.out.println("Cannot add a duplicate.\n"); iter = ss.iterator(); while (iter.hasNext()) System.out.println(iter.next()); }
From source file:Main.java
public static void main(String[] s) { SortedSet<String> set = new TreeSet<String>(); set.add("Welcome"); set.add("to"); set.add("java2s.com"); System.out.println("Initial set value: " + set); // create unmodifiable sorted set Set<String> unmodsortset = Collections.unmodifiableSortedSet(set); // try to modify the sorted set unmodsortset.add("Hello"); }
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:MainClass.java
public static void main(String args[]) throws Exception { String elements[] = { "S", "P", "E", "G", "P" }; Set set = new TreeSet(Collections.reverseOrder()); for (int i = 0, n = elements.length; i < n; i++) { set.add(elements[i]); }//from w w w . j a v a2 s.c o m System.out.println(set); System.out.println(((TreeSet) set).comparator()); }
From source file:Main.java
public static void main(String[] args) { Set<Integer> intSet = new LinkedHashSet<Integer>(); Random r = new Random(); while (intSet.size() <= 6) { intSet.add(r.nextInt(49)); }//from w w w . jav a2 s . c om System.out.println(intSet); }
From source file:Main.java
public static void main(String args[]) { Employee emps[] = { new Employee("Finance", "Degree, Debbie"), new Employee("Finance", "Grade, Geri"), new Employee("Finance", "Extent, Ester"), new Employee("Engineering", "Measure, Mary"), new Employee("Engineering", "Amount, Anastasia"), new Employee("Engineering", "Ratio, Ringo"), new Employee("Sales", "Stint, Sarah"), new Employee("Sales", "Pitch, Paula"), new Employee("Support", "Rate, Rhoda"), }; SortedSet set = new TreeSet(Arrays.asList(emps)); System.out.println(set);/*www .j ava 2 s.com*/ try { Object last = set.last(); boolean first = true; while (true) { if (!first) { System.out.print(", "); } System.out.println(last); last = set.headSet(last).last(); } } catch (NoSuchElementException e) { System.out.println(); } Set subset = set.headSet(emps[4]); subset.add(emps[5]); }