List of usage examples for java.util Set iterator
Iterator<E> iterator();
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 w w w .j a v a 2s. co m*/ }
From source file:Main.java
public static void main(String[] a) { Map<String, String> yourMap = new HashMap<String, String>(); yourMap.put("1", "one"); yourMap.put("2", "two"); yourMap.put("3", "three"); Map<String, Object> map = new LinkedHashMap<String, Object>(); List<String> keyList = new ArrayList<String>(yourMap.keySet()); List<String> valueList = new ArrayList<String>(yourMap.values()); Set<String> sortedSet = new TreeSet<String>(valueList); Object[] sortedArray = sortedSet.toArray(); int size = sortedArray.length; for (int i = 0; i < size; i++) { map.put(keyList.get(valueList.indexOf(sortedArray[i])), sortedArray[i]); }// ww w.ja v a2 s . c om Set ref = map.keySet(); Iterator it = ref.iterator(); while (it.hasNext()) { String i = (String) it.next(); System.out.println(i); } }
From source file:Main.java
public static void main(String[] args) { Integer[] numbers = { 7, 7, 8, 9, 10, 8, 8, 9, 6, 5, 4 }; List<Integer> list = Arrays.asList(numbers); Set<Integer> set = new HashSet<Integer>(list); for (Iterator iterator = set.iterator(); iterator.hasNext();) { Object o = iterator.next(); System.out.print(o + ", "); }/*from ww w . ja v a 2 s . c o m*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { Set result = new HashSet(); String serviceType = "KeyFactory"; Provider[] providers = Security.getProviders(); for (int i = 0; i < providers.length; i++) { Set keys = providers[i].keySet(); for (Iterator it = keys.iterator(); it.hasNext();) { String key = (String) it.next(); key = key.split(" ")[0]; if (key.startsWith(serviceType + ".")) { result.add(key.substring(serviceType.length() + 1)); } else if (key.startsWith("Alg.Alias." + serviceType + ".")) { result.add(key.substring(serviceType.length() + 11)); }// ww w .ja va 2s. c o m } } System.out.println(result); }
From source file:Main.java
public static void main(String[] args) { HashMap<String, Integer> map = new HashMap<String, Integer>(); map.put("d", 5); map.put("c", 4); map.put("b", 2); map.put("a", 1); Integer value[] = new Integer[map.size()]; Set keySet = map.keySet(); Iterator t = keySet.iterator(); int a = 0;/*from ww w . java 2s.c o m*/ while (t.hasNext()) { value[a] = map.get(t.next()); a++; } Arrays.sort(value); for (int i = 0; i < map.size(); i++) { t = keySet.iterator(); while (t.hasNext()) { String temp = (String) t.next(); if (value[i].equals(map.get(temp))) { System.out.println(value[i] + " = " + temp); } } } }
From source file:Main.java
public static void main(String[] args) throws Exception { Set defaults = UIManager.getLookAndFeelDefaults().entrySet(); for (Iterator i = defaults.iterator(); i.hasNext();) { Map.Entry entry = (Map.Entry) i.next(); System.out.print(entry.getKey() + " = "); System.out.println(entry.getValue()); }//from www.j a va2 s .c om }
From source file:HashMapExample.java
public static void main(String[] args) { Map<Integer, String> map = new HashMap<Integer, String>(); map.put(new Integer(1), "One"); map.put(new Integer(2), "Two"); map.put(new Integer(3), "Three"); map.put(new Integer(4), "Four"); map.put(new Integer(5), "Five"); System.out.println("Map Values Before: "); Set keys = map.keySet(); for (Iterator i = keys.iterator(); i.hasNext();) { Integer key = (Integer) i.next(); String value = (String) map.get(key); System.out.println(key + " = " + value); }//from www.jav a 2 s . c o m System.out.println("\nRemove element with key 6"); map.remove(new Integer(6)); System.out.println("\nMap Values After: "); keys = map.keySet(); for (Iterator i = keys.iterator(); i.hasNext();) { Integer key = (Integer) i.next(); String value = (String) map.get(key); System.out.println(key + " = " + value); } }
From source file:HTDemo2.java
public static void main(String args[]) { Hashtable<String, Double> balance = new Hashtable<String, Double>(); String str;//w w w.j a v a 2 s .c o m double bal; balance.put("A", 3434.34); balance.put("B", 123.22); balance.put("C", 1378.00); balance.put("D", 99.22); balance.put("E", -19.08); Set<String> set = balance.keySet(); Iterator<String> itr = set.iterator(); while (itr.hasNext()) { str = itr.next(); System.out.println(str + ": " + balance.get(str)); } System.out.println(); bal = balance.get("A"); balance.put("A", bal + 1000); System.out.println("A's new balance: " + balance.get("A")); }
From source file:TreeMapExample.java
public static void main(String[] args) { Map<Integer, String> map = new TreeMap<Integer, String>(); // Add Items to the TreeMap map.put(new Integer(1), "One"); map.put(new Integer(2), "Two"); map.put(new Integer(3), "Three"); map.put(new Integer(4), "Four"); map.put(new Integer(5), "Five"); map.put(new Integer(6), "Six"); map.put(new Integer(7), "Seven"); map.put(new Integer(8), "Eight"); map.put(new Integer(9), "Nine"); map.put(new Integer(10), "Ten"); // Use iterator to display the keys and associated values System.out.println("Map Values Before: "); Set keys = map.keySet(); for (Iterator i = keys.iterator(); i.hasNext();) { Integer key = (Integer) i.next(); String value = (String) map.get(key); System.out.println(key + " = " + value); }//w ww .ja va2s . c o m // Remove the entry with key 6 System.out.println("\nRemove element with key 6"); map.remove(new Integer(6)); // Use iterator to display the keys and associated values System.out.println("\nMap Values After: "); keys = map.keySet(); for (Iterator i = keys.iterator(); i.hasNext();) { Integer key = (Integer) i.next(); String value = (String) map.get(key); System.out.println(key + " = " + value); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { Set result = new HashSet(); Provider[] providers = Security.getProviders(); for (int i = 0; i < providers.length; i++) { Set keys = providers[i].keySet(); for (Iterator it = keys.iterator(); it.hasNext();) { String key = (String) it.next(); key = key.split(" ")[0]; if (key.startsWith("Alg.Alias.")) { // Strip the alias key = key.substring(10);//from ww w. j av a 2 s . c o m } int ix = key.indexOf('.'); result.add(key.substring(0, ix)); } } System.out.println(result); }