List of usage examples for java.util Iterator next
E next();
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> tree = new TreeSet<Integer>(); tree.add(12);//from w w w . j av a 2 s . c o m tree.add(13); tree.add(14); // cloning tree into clinetree TreeSet<Integer> clonetree = (TreeSet) tree.clone(); // creating iterator Iterator<Integer> iterator = clonetree.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } }
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]); }//from w w w .ja v a 2s . c o m 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) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(12);/* w ww. ja va 2 s. c o m*/ treeadd.add(13); treeadd.add(14); treeadd.add(15); Iterator<Integer> iterator = treeadd.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } treeadd.clear(); System.out.println(treeadd.size()); }
From source file:DumpProps.java
public static void main(String args[]) { Properties props = System.getProperties(); Iterator iter = props.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); System.out.println(entry.getKey() + " --- " + entry.getValue()); }//from w w w .j a va2 s . c om System.out.println("-------"); Enumeration e = props.propertyNames(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); System.out.println(key + " --- " + props.getProperty(key)); } }
From source file:SetDemo.java
public static void main(String[] argv) { //+// ww w . j a v a 2 s . co 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:DynaBeansExampleV2.java
public static void main(String args[]) throws Exception { Connection conn = getConnection(); PreparedStatement ps = conn// w w w . j av a 2 s .c o m .prepareStatement("SELECT * from movie, person " + "WHERE movie.director = person.Id"); ResultSet rs = ps.executeQuery(); ResultSetDynaClass rsdc = new ResultSetDynaClass(rs); Iterator itr = rsdc.iterator(); while (itr.hasNext()) { DynaBean bean = (DynaBean) itr.next(); System.err.println(bean.get("title")); } conn.close(); }
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 ava2s .c o 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) throws Exception { String url = "http://www.java2s.com"; Document doc = Jsoup.connect(url).userAgent( "Mozilla/5.0 (Windows; U; WindowsNT 5.1;" + " en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6") .get();//from w ww . jav a 2 s . c o m Elements resultDivElems = doc.select("div"); Iterator<Element> itr = resultDivElems.iterator(); while (itr.hasNext()) { System.out.println(((Element) itr.next()).text()); } }
From source file:Main.java
public static void main(String[] args) throws Exception { // Prepare content for simulating property files String fileContent = "s1=1\n" + "s2=Main\n" + "s3=Fri Jan 31 00:00:00 IST 3913"; InputStream propStream = new StringBufferInputStream(fileContent); // Create property resource bundle PropertyResourceBundle bundle = new Main(propStream); // Get resource key set Set keySet = bundle.handleKeySet(); Iterator keys = keySet.iterator(); while (keys.hasNext()) { System.out.println("Bundle key: " + keys.next()); }//ww w.j a v a2 s . com }
From source file:Main.java
public static void main(String[] args) { Map<String, int[]> map = new TreeMap<String, int[]>(); int[] array = new int[3]; array[0] = 0;// ww w.j av a 2 s . co m array[1] = 1; array[2] = 2; map.put("array", array); Iterator<String> iter = map.keySet().iterator(); while (iter.hasNext()) { String arrayName = iter.next(); array = map.get(arrayName); System.out.print(arrayName + ":"); for (int i = 0; i < array.length; i++) { System.out.print(array[i]); } } }