List of usage examples for java.util Iterator next
E next();
From source file:Main.java
public static void main(String[] args) { HashMap<String, Integer> myMap = new HashMap<String, Integer>(); myMap.put("a", 1); myMap.put("b", 2); myMap.put("c", 3); Set<String> stStrKeys = myMap.keySet(); Iterator<String> itrs = stStrKeys.iterator(); while (itrs.hasNext()) { String s = itrs.next(); System.out.println(s + ": " + myMap.get(s)); }/* w ww. jav a 2 s . com*/ }
From source file:NewStyle.java
public static void main(String args[]) { ArrayList<String> list = new ArrayList<String>(); list.add("one"); list.add("two"); list.add("three"); list.add("four"); Iterator<String> itr = list.iterator(); while (itr.hasNext()) { String str = itr.next(); // no cast needed System.out.println(str + " is " + str.length() + " chars long."); }// w w w .ja va 2 s . c o m }
From source file:Main.java
public static void main(String[] args) { Hashtable<String, String> ht = new Hashtable<String, String>(); ht.put("1", "One"); ht.put("2", "Two"); ht.put("3", "Three"); Collection c = ht.values();//w ww.j a v a2s . c om Iterator itr = c.iterator(); while (itr.hasNext()) { System.out.println(itr.next()); } c.remove("One"); Enumeration e = ht.elements(); while (e.hasMoreElements()) { System.out.println(e.nextElement()); } }
From source file:Main.java
public static void main(String[] args) { Map map = System.getenv(); Set keys = map.keySet();/* www. j ava 2s .c o m*/ Iterator iterator = keys.iterator(); while (iterator.hasNext()) { String key = (String) iterator.next(); String value = (String) map.get(key); System.out.println(key + " = " + value); } }
From source file:Main.java
public static void main(String[] args) { String[] array = { "A", "B", "C", "D" }; List list = Arrays.asList(array); Iterator iterator = list.iterator(); while (iterator.hasNext()) { System.out.println((String) iterator.next()); }/*from w ww . j a v a2 s . co m*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { Iterator it = Arrays.asList("a", "b", "java2s.com").iterator(); while (it.hasNext()) { String key = it.next().toString(); System.out.println(key);/*from w w w. j av a 2 s. c om*/ } }
From source file:MainClass.java
public static void main(String[] args) { Map charsets = Charset.availableCharsets(); Iterator iterator = charsets.keySet().iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); }/* www . j a v a 2s .c om*/ }
From source file:Main.java
public static void main(String args[]) { PriorityQueue<Integer> prq = new PriorityQueue<Integer>(); for (int i = 0; i < 10; i++) { prq.add(i);/*from w w w . j ava2 s.c o m*/ } // create iterator from the queue Iterator it = prq.iterator(); while (it.hasNext()) { System.out.println("Value: " + it.next()); } }
From source file:ItemSet.java
public static void main(String args[]) { String names[] = { "Item 1", "Item 2", "Item 3" }; Set moons = new HashSet(); int namesLen = names.length; int index;//from w w w. j a v a 2 s . co m for (int i = 0; i < 100; i++) { index = (int) (Math.random() * namesLen); moons.add(names[index]); } Iterator it = moons.iterator(); while (it.hasNext()) { System.out.println(it.next()); } System.out.println("---"); Set orderedMoons = new TreeSet(moons); it = orderedMoons.iterator(); while (it.hasNext()) { System.out.println(it.next()); } }
From source file:DiameterMap.java
public static void main(String args[]) { String names[] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto" }; float diameters[] = { 4800f, 12103.6f, 12756.3f, 6794f, 142984f, 120536f, 51118f, 49532f, 2274f }; Map map = new TreeMap(); for (int i = 0, n = names.length; i < n; i++) { map.put(names[i], new Float(diameters[i])); }/* w w w .ja v a2 s . com*/ Iterator it = map.keySet().iterator(); Object obj; while (it.hasNext()) { obj = it.next(); System.out.println(obj + ": " + map.get(obj)); } }