List of usage examples for java.util Iterator next
E next();
From source file:SetTest.java
public static void main(String[] args) { Set<String> words = new HashSet<String>(); // HashSet implements Set long totalTime = 0; Scanner in = new Scanner(System.in); while (in.hasNext()) { String word = in.next();//from ww w .j a va 2 s . co m long callTime = System.currentTimeMillis(); words.add(word); callTime = System.currentTimeMillis() - callTime; totalTime += callTime; } Iterator<String> iter = words.iterator(); for (int i = 1; i <= 20 && iter.hasNext(); i++) System.out.println(iter.next()); System.out.println(". . ."); System.out.println(words.size() + " distinct words. " + totalTime + " milliseconds."); }
From source file:SortedMapDemo.java
public static void main(String[] args) { TreeMap sortedMap = new TreeMap(); sortedMap.put("Adobe", "Mountain View, CA"); sortedMap.put("IBM", "White Plains, NY"); sortedMap.put("Learning Tree", "Los Angeles, CA"); sortedMap.put("Microsoft", "Redmond, WA"); sortedMap.put("Netscape", "Mountain View, CA"); sortedMap.put("O'Reilly", "Sebastopol, CA"); sortedMap.put("Sun", "Mountain View, CA"); System.out.println(sortedMap); Object low = sortedMap.firstKey(), high = sortedMap.lastKey(); System.out.println(low);//from www . j av a 2 s. co m System.out.println(high); Iterator it = sortedMap.keySet().iterator(); for (int i = 0; i <= 6; i++) { if (i == 3) low = it.next(); if (i == 6) high = it.next(); else it.next(); } System.out.println(low); System.out.println(high); System.out.println(sortedMap.subMap(low, high)); System.out.println(sortedMap.headMap(high)); System.out.println(sortedMap.tailMap(low)); }
From source file:HelloPeopleJDOM.java
public static void main(String[] args) throws Exception { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build("./src/data.xml"); StringBuffer output = new StringBuffer(); // create the basic HTML output output.append("<html>\n").append("<head>\n<title>\nPerson List</title>\n</head>\n").append("<body>\n") .append("<ul>\n"); Iterator itr = doc.getRootElement().getChildren().iterator(); while (itr.hasNext()) { Element elem = (Element) itr.next(); output.append("<li>"); output.append(elem.getAttribute("lastName").getValue()); output.append(", "); output.append(elem.getAttribute("firstName").getValue()); output.append("</li>\n"); }/*from w ww . j av a2s.co m*/ // create the end of the HTML output output.append("</ul>\n</body>\n</html>"); System.out.println(output.toString()); }
From source file:SetExampleV2.java
public static void main(String args[]) { // create two sets Set set1 = new HashSet(); set1.add("Red"); set1.add("Green"); Set set2 = new HashSet(); set2.add("Yellow"); set2.add("Red"); // create a composite set out of these two CompositeSet composite = new CompositeSet(); // set the class that handles additions, conflicts etc // composite.setMutator(new CompositeMutator()); // initialize the composite with the sets // Cannot be used if set1 and set2 intersect is not null and // a strategy to deal with it has not been set composite.addComposited(new Set[] { set1, set2 }); // do some addition/deletions // composite.add("Pink"); // composite.remove("Green"); // whats left in the composite? Iterator itr = composite.iterator(); while (itr.hasNext()) { System.err.println(itr.next()); }/*from w ww .jav a2 s. c om*/ }
From source file:au.org.ala.layers.client.Client.java
public static void main(String[] args) { System.out.println("Layers Store CLI client"); ApplicationContext context = new ClassPathXmlApplicationContext("spring/app-config.xml"); LayerDAO layerDao = (LayerDAO) context.getBean("layerDao"); List<Layer> layers = layerDao.getLayers(); System.out.println("Got " + layers.size() + " layers"); Iterator<Layer> it = layers.iterator(); while (it.hasNext()) { Layer l = it.next(); System.out.println(" > " + l.getName()); }/* w w w . ja v a 2s .co m*/ }
From source file:com.github.xbn.examples.io.non_xbn.SizeOrderAllFilesInDirXmpl.java
public static final void main(String[] ignored) { File fDir = (new File("R:\\jeffy\\programming\\sandbox\\xbnjava\\xbn\\")); Collection<File> cllf = FileUtils.listFiles(fDir, (new String[] { "java" }), true); //Add all file paths to a Map, keyed by size. //It's actually a map of lists-of-files, to //allow multiple files that happen to have the //same length. TreeMap<Long, List<File>> tmFilesBySize = new TreeMap<Long, List<File>>(); Iterator<File> itrf = cllf.iterator(); while (itrf.hasNext()) { File f = itrf.next(); Long LLen = f.length();//from w ww . j a v a2 s . c o m if (!tmFilesBySize.containsKey(LLen)) { ArrayList<File> alf = new ArrayList<File>(); alf.add(f); tmFilesBySize.put(LLen, alf); } else { tmFilesBySize.get(LLen).add(f); } } //Iterate backwards by key through the map. For each //List<File>, iterate through the files, printing out //its size and path. ArrayList<Long> alSize = new ArrayList<Long>(tmFilesBySize.keySet()); for (int i = alSize.size() - 1; i >= 0; i--) { itrf = tmFilesBySize.get(alSize.get(i)).iterator(); while (itrf.hasNext()) { File f = itrf.next(); System.out.println(f.length() + ": " + f.getPath()); } } }
From source file:json.ReadFromFile.java
public static void main(String[] args) { JSONParser parser = new JSONParser(); try {//from w ww . ja v a2 s . co m Object obj = parser.parse(new FileReader(file)); JSONObject jsonObject = (JSONObject) obj; String countryName = jsonObject.get("Name") + "";//equivalent to jsonObject.get("Name").toString(); System.out.println("Name of Country: " + countryName); long population = (long) jsonObject.get("Population"); System.out.println("Population: " + population); System.out.println("Counties are:"); JSONArray listOfCounties = (JSONArray) jsonObject.get("Counties"); Iterator<String> iterator = listOfCounties.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } } catch (IOException | ParseException e) { e.printStackTrace(); } }
From source file:jsonpractice.jsonpractice1.java
public static void main(String[] args) throws IOException, ParseException { JSONParser parser = new JSONParser(); try {// w w w .ja v a 2 s.c o m Object obj = parser.parse(new FileReader("C:\\Users\\user\\Documents\\CountryJSONFile.json")); JSONObject jsonobject = (JSONObject) obj; String nameOfCountry = (String) jsonobject.get("Name"); System.out.println("Name of the Country: " + nameOfCountry); long population = (long) jsonobject.get("Population"); System.out.println("Population of the country is : " + population); System.out.println("States are: "); JSONArray listOfStates = (JSONArray) jsonobject.get("states"); Iterator<String> iterator = listOfStates.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } } catch (FileNotFoundException e) { } catch (IOException e) { } catch (ParseException e) { } }
From source file:MapEntrySetDemo.java
public static void main(String[] argv) { // Construct and load the hash. This simulates loading a // database or reading from a file, or wherever the data is. Map map = new HashMap(); // The hash maps from company name to address. // In real life this might map to an Address object... map.put("Adobe", "Mountain View, CA"); map.put("IBM", "White Plains, NY"); map.put("Learning Tree", "Los Angeles, CA"); map.put("Microsoft", "Redmond, WA"); map.put("Netscape", "Mountain View, CA"); map.put("O'Reilly", "Sebastopol, CA"); map.put("Sun", "Mountain View, CA"); // List the entries using entrySet() Set entries = map.entrySet(); Iterator it = entries.iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); System.out.println(entry.getKey() + "-->" + entry.getValue()); }// w w w . j ava 2 s . co m }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(1);/*from ww w .j av a2 s . c om*/ treeadd.add(13); treeadd.add(17); treeadd.add(2); // creating reverse set TreeSet<Integer> treereverse = (TreeSet<Integer>) treeadd.descendingSet(); // create descending set Iterator<Integer> iterator = treereverse.iterator(); //Tree set data in reverse order while (iterator.hasNext()) { System.out.println(iterator.next()); } }