List of usage examples for java.util Iterator hasNext
boolean hasNext();
From source file:Main.java
public static void main(String[] argv) { // Create the sorted set Set<String> set = new TreeSet<String>(); set.add("b"); set.add("c"); set.add("a"); Iterator it = set.iterator(); while (it.hasNext()) { Object element = it.next(); System.out.println(element); }//from ww w . j a va 2s .c o m // Create an array containing the elements in a set String[] array = (String[]) set.toArray(new String[set.size()]); Arrays.toString(array); }
From source file:Main.java
public static void main(String[] args) throws IOException { String fileContent = "s1=1\n" + "s2=Main\n" + "s3=Fri Jan 31 00:00:00 IST 3913"; InputStream propStream = new StringBufferInputStream(fileContent); 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()); }/*w ww .jav a2 s.co m*/ }
From source file:MainClass.java
public static void main(String[] args) { Provider provider = Security.getProvider("BC"); Iterator it = provider.keySet().iterator(); while (it.hasNext()) { String entry = (String) it.next(); if (entry.startsWith("Alg.Alias.")) { entry = entry.substring("Alg.Alias.".length()); }// ww w . j ava 2 s. com System.out.println(entry); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Document doc = new SAXBuilder().build("books.xml"); Element books = doc.getRootElement(); Iterator it = books.getChildren().iterator(); while (it.hasNext()) { Element book = (Element) it.next(); System.out.println(book.getChildText("name") + " was published in " + book.getChildText("pubDate")); }/*from w w w .ja v a2s . c om*/ }
From source file:Main.java
public static void main(String[] args) { String text = "A,B,C,D"; String[] keyValue = text.split(","); Map<Integer, String> myMap = new HashMap<Integer, String>(); for (int i = 0; i < keyValue.length; i++) { myMap.put(i, keyValue[i]);//from ww w. j a v a 2s. c o m } Set keys = myMap.keySet(); Iterator itr = keys.iterator(); while (itr.hasNext()) { Integer key = (Integer) itr.next(); String value = (String) myMap.get(key); System.out.println(key + " - " + value); } }
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 av a 2 s. c o 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: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()); }/*www. j a va 2s . c o m*/ }
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."); }//from ww w . ja va2 s .c o m }
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();/*from w w w . ja v a2 s.c o m*/ System.out.println(s + ": " + myMap.get(s)); } }
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 av a 2s . c o m*/ } }