List of usage examples for java.util Iterator hasNext
boolean hasNext();
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> tree = new TreeSet<Integer>(); tree.add(12);/*from www. j a v a 2 s .co m*/ tree.add(13); tree.add(14); tree.add(15); tree.add(16); tree.add(17); // getting values less than 15 TreeSet<Integer> treeheadset = (TreeSet) tree.headSet(15); Iterator<Integer> iterator = treeheadset.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } }
From source file:SetDemo.java
public static void main(String[] argv) { //+/*ww w. jav a 2 s . c o m*/ Set h = new HashSet(); h.add("One"); h.add("Two"); h.add("One"); // DUPLICATE h.add("Three"); Iterator it = h.iterator(); while (it.hasNext()) { System.out.println(it.next()); } //- }
From source file:PreferencesDemo.java
public static void main(String[] args) throws Exception { Preferences prefs = Preferences.userNodeForPackage(PreferencesDemo.class); prefs.put("Location", "Oz"); prefs.put("Footwear", "Ruby Slippers"); prefs.putInt("Companions", 4); prefs.putBoolean("Are there witches?", true); int usageCount = prefs.getInt("UsageCount", 0); usageCount++;/*w w w .j a v a 2 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)); } // You must always provide a default value: System.out.println("How many companions does Dorothy have? " + prefs.getInt("Companions", 0)); }
From source file:MovingPlanets.java
public static void main(String args[]) { String names[] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto" }; List planets = new ArrayList(); for (int i = 0, n = names.length; i < n; i++) { planets.add(names[i]);//from w w w . j a v a2s . co m } ListIterator lit = planets.listIterator(); String s; lit.next(); lit.next(); s = (String) lit.next(); lit.remove(); lit.next(); lit.next(); lit.next(); lit.add(s); lit.next(); // Gets back just added lit.previous(); lit.previous(); s = (String) lit.previous(); lit.remove(); lit.next(); lit.next(); lit.add(s); Iterator it = planets.iterator(); while (it.hasNext()) { System.out.println(it.next()); } }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeone = new TreeSet<Integer>(); TreeSet<Integer> treetwo = new TreeSet<Integer>(); treeone.add(12);//ww w.j a va 2 s . com treeone.add(13); treeone.add(14); treetwo.add(15); treetwo.add(16); treetwo.add(17); // adding treetwo to treeone treeone.addAll(treetwo); Iterator<Integer> iterator = treeone.iterator(); while (iterator.hasNext()) { System.out.print(iterator.next()); } }
From source file:SyncTest.java
public static void main(String args[]) { Set simpsons = new HashSet(); simpsons.add("Bart"); simpsons.add("Hugo"); simpsons.add("Lisa"); simpsons.add("Marge"); simpsons.add("Homer"); simpsons.add("Maggie"); simpsons.add("Roy"); simpsons = Collections.synchronizedSet(simpsons); synchronized (simpsons) { Iterator iter = simpsons.iterator(); while (iter.hasNext()) { System.out.println(iter.next()); }// w w w.j av a 2s .c o m } Map map = Collections.synchronizedMap(new HashMap(89)); Set set = map.entrySet(); synchronized (map) { Iterator iter = set.iterator(); while (iter.hasNext()) { System.out.println(iter.next()); } } }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(1);/* w w w .j a v a 2 s . c om*/ treeadd.add(2); treeadd.add(3); treeadd.add(4); treeadd.add(5); treeadd.add(6); treeadd.add(7); treeadd.add(8); TreeSet<Integer> treesubset = (TreeSet<Integer>) treeadd.subSet(3, 7); Iterator<Integer> iterator = treesubset.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(1);/*ww w . ja v a2 s . c o m*/ treeadd.add(2); treeadd.add(3); treeadd.add(4); treeadd.add(5); treeadd.add(6); treeadd.add(7); treeadd.add(8); TreeSet<Integer> treesubset = (TreeSet<Integer>) treeadd.subSet(3, true, 7, true); Iterator<Integer> iterator = treesubset.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } }
From source file:Main.java
public static void main(String args[]) { HashSet<String> newset = new HashSet<String>(); // populate hash set newset.add("Learning"); newset.add("from"); newset.add("java2s.com"); // create an iterator Iterator iterator = newset.iterator(); // check values while (iterator.hasNext()) { System.out.println("Value: " + iterator.next() + " "); }//from w ww . j a v a2 s .co m }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(1);//w ww. j a va 2 s . c o m treeadd.add(2); treeadd.add(3); treeadd.add(4); treeadd.add(5); treeadd.add(6); treeadd.add(7); treeadd.add(8); TreeSet<Integer> treetailset = (TreeSet<Integer>) treeadd.tailSet(4); Iterator<Integer> iterator = treetailset.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } }