List of usage examples for java.util Iterator next
E next();
From source file:Main.java
public static void main(String args[]) { ArrayList<Integer> arrlist = new ArrayList<Integer>(); arrlist.add(1);//from w w w . ja va 2s . c om arrlist.add(2); arrlist.add(3); arrlist.add(4); arrlist.add(5); Iterator<Integer> iterator = arrlist.iterator(); while (iterator.hasNext()) { Integer i = iterator.next(); System.out.println(i); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Preferences prefs = Preferences.userNodeForPackage(MainClass.class); prefs.put("key1", "value1"); prefs.put("key2", "value2"); prefs.putInt("intValue", 4); prefs.putBoolean("booleanValue", true); int usageCount = prefs.getInt("intValue", 0); usageCount++;/*w w w . jav a 2s .c om*/ prefs.putInt("UsageCount", usageCount); Iterator it = Arrays.asList(prefs.keys()).iterator(); while (it.hasNext()) { String key = it.next().toString(); System.out.println(key + ": " + prefs.get(key, null)); } System.out.println(prefs.getInt("booleanValue", 0)); }
From source file:Main.java
public static void main(String[] args) throws Exception { Preferences prefs = Preferences.userNodeForPackage(Main.class); prefs.put("key1", "value1"); prefs.put("key2", "value2"); prefs.putInt("intValue", 4); prefs.putBoolean("booleanValue", true); int usageCount = prefs.getInt("intValue", 0); usageCount++;//from www . ja v a2 s.c o m prefs.putInt("UsageCount", usageCount); Iterator it = Arrays.asList(prefs.keys()).iterator(); while (it.hasNext()) { String key = it.next().toString(); System.out.println(key + ": " + prefs.get(key, null)); } System.out.println(prefs.getInt("booleanValue", 0)); }
From source file:SafeCollectionIteration.java
public static void main(String[] args) { List wordList = Collections.synchronizedList(new ArrayList()); wordList.add("Iterators"); wordList.add("require"); wordList.add("special"); wordList.add("handling"); synchronized (wordList) { Iterator iter = wordList.iterator(); while (iter.hasNext()) { String s = (String) iter.next(); System.out.println("found string: " + s + ", length=" + s.length()); }//from w w w.j a v a 2 s . c om } }
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"); Set st = ht.keySet();/*ww w.j av a 2 s. c om*/ Iterator itr = st.iterator(); while (itr.hasNext()) { System.out.println(itr.next()); } st.remove("2"); Enumeration e = ht.keys(); while (e.hasMoreElements()) { System.out.println(e.nextElement()); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { Object keyObject = ""; Object valueObject = ""; Map<Object, Object> weakMap = new WeakHashMap<Object, Object>(); weakMap.put(keyObject, valueObject); WeakReference weakValue = new WeakReference<Object>(valueObject); weakMap.put(keyObject, weakValue);/*from www. j a v a 2s. c om*/ Iterator it = weakMap.keySet().iterator(); while (it.hasNext()) { Object key = it.next(); weakValue = (WeakReference) weakMap.get(key); if (weakValue == null) { System.out.println("Value has been garbage-collected"); } else { System.out.println("Get value"); valueObject = weakValue.get(); } } }
From source file:Main.java
public static void main(String[] argv) throws Exception { Map<String, Integer> map = new HashMap<String, Integer>(); map = new TreeMap(); map.put("a", new Integer(1)); map.put("b", new Integer(2)); map.put("c", new Integer(3)); int size = map.size(); // 2 Object oldValue = map.put("a", new Integer(9)); // 1 oldValue = map.remove("c"); // 3 Iterator it = map.keySet().iterator(); while (it.hasNext()) { Object key = it.next(); }// w w w . j a v a 2 s . c om it = map.values().iterator(); while (it.hasNext()) { Object value = it.next(); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { Object keyObject = ""; Object valueObject = ""; Map weakMap = new WeakHashMap(); weakMap.put(keyObject, valueObject); WeakReference weakValue = new WeakReference(valueObject); weakMap.put(keyObject, weakValue);/*w w w .j av a2 s.c o m*/ Iterator it = weakMap.keySet().iterator(); while (it.hasNext()) { Object key = it.next(); weakValue = (WeakReference) weakMap.get(key); if (weakValue == null) { System.out.println("Value has been garbage-collected"); } else { System.out.println("Get value"); valueObject = weakValue.get(); } } }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(12);//from w w w . ja va 2 s .c om treeadd.add(13); treeadd.add(14); treeadd.add(15); Iterator<Integer> iterator = treeadd.iterator(); while (iterator.hasNext()) { System.out.print(iterator.next()); } }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(1);/*from ww w. j a v a 2 s.co m*/ treeadd.add(13); treeadd.add(17); treeadd.add(22); Iterator<Integer> iterator = treeadd.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } }