List of usage examples for java.util Set size
int size();
From source file:Main.java
public static void main(final String[] args) throws Exception { Random random = new Random(); Set<Integer> intSet = new HashSet<>(); while (intSet.size() < 6) { intSet.add(random.nextInt(49) + 1); }/*www . ja v a 2 s. c om*/ Integer[] ints = intSet.toArray(new Integer[intSet.size()]); System.out.println(Arrays.toString(ints)); }
From source file:Main.java
public static void main(String[] args) { Random random = new Random(); Set<Integer> set = new HashSet<Integer>(); while (set.size() < 5) { set.add(random.nextInt());//from w ww . ja v a 2 s. c o m } List<Integer> result = new ArrayList<Integer>(set); System.out.println(result); }
From source file:Main.java
public static void main(String[] a) { String elements[] = { "A", "B", "C", "D", "E" }; Set<String> set = new HashSet<String>(Arrays.asList(elements)); System.out.println(set.size()); }
From source file:Main.java
public static void main(String[] args) { String elements[] = { "M", "N", "O", "P", "Q" }; Set set = new HashSet(Arrays.asList(elements)); String[] strObj = new String[set.size()]; strObj = (String[]) set.toArray(strObj); for (int i = 0; i < strObj.length; i++) { System.out.println(strObj[i]); }// ww w. j a v a2s . c o m System.out.println(set); }
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)); String[] strObj = new String[set.size()]; strObj = (String[]) set.toArray(strObj); for (int i = 0; i < strObj.length; i++) { System.out.println(strObj[i]); }/*from w ww . j av a 2s . com*/ System.out.println(set); }
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));// w w w. ja v a2 s. c o m } System.out.println(intSet); }
From source file:Main.java
public static void main(String[] args) { Map<String, Charset> map = Charset.availableCharsets(); Set<String> keys = map.keySet(); System.out.println("Available Character Set Count: " + keys.size()); for (String charsetName : keys) { System.out.println(charsetName); }/*from w w w . j a v a2 s . co m*/ }
From source file:FindDups.java
public static void main(String[] args) { Set<String> s = new HashSet<String>(); for (String a : args) s.add(a);/*from w w w . j ava 2 s . c o m*/ System.out.println(s.size() + " distinct words: " + s); }
From source file:Main.java
public static void main(String[] args) { // A string array with duplicate values String[] data = { "A", "C", "B", "D", "A", "B", "E", "D", "B", "C" }; System.out.println("Original array : " + Arrays.toString(data)); List<String> list = Arrays.asList(data); Set<String> set = new HashSet<String>(list); System.out.print("Remove duplicate result: "); String[] result = new String[set.size()]; set.toArray(result);/* w w w. j a v a2 s . c o m*/ for (String s : result) { System.out.print(s + ", "); } }
From source file:FindDups.java
public static void main(String[] args) { Set<String> s = new HashSet<String>(); for (String a : args) if (!s.add(a)) System.out.println("Duplicate detected: " + a); System.out.println(s.size() + " distinct words: " + s); }