List of usage examples for java.util Iterator next
E next();
From source file:SortedSetDemo.java
public static void main(String[] args) { SortedSet sortedSet = new TreeSet(Arrays.asList("one two three four five six seven eight".split(" "))); System.out.println(sortedSet); Object low = sortedSet.first(), high = sortedSet.last(); System.out.println(low);//w w w. ja v a 2 s .c o m System.out.println(high); Iterator it = sortedSet.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(sortedSet.subSet(low, high)); System.out.println(sortedSet.headSet(high)); System.out.println(sortedSet.tailSet(low)); }
From source file:Main.java
public static void main(String[] args) { HashMap<String, Integer> map = new HashMap<String, Integer>(); map.put("d", 5); map.put("c", 4); map.put("b", 2); map.put("a", 1); Integer value[] = new Integer[map.size()]; Set keySet = map.keySet();//from w ww . j a v a 2 s . com Iterator t = keySet.iterator(); int a = 0; while (t.hasNext()) { value[a] = map.get(t.next()); a++; } Arrays.sort(value); for (int i = 0; i < map.size(); i++) { t = keySet.iterator(); while (t.hasNext()) { String temp = (String) t.next(); if (value[i].equals(map.get(temp))) { System.out.println(value[i] + " = " + temp); } } } }
From source file:la.alsocan.jsonshapeshifter.Main.java
/** * An entry point, to test the library in action. * @param args Console args (nothing expected here so far) * @throws IOException if the payload cannot be read *///from ww w . j av a2s . c om public static void main(String[] args) throws IOException { Schema source; Schema target; try { source = Schema.buildSchema(SOURCE_SCHEMA); target = Schema.buildSchema(TARGET_SCHEMA); } catch (IOException ex) { System.err.println("Oups: " + ex); return; } // build the transformation incrementally Transformation t = new Transformation(source, target); Iterator<SchemaNode> it = t.toBind(); t.bind(it.next(), new ArrayNodeBinding(source.at("/rootSourceArray"))); t.bind(it.next(), new ArrayNodeBinding(source.at("/rootSourceArray/{i}"))); t.bind(it.next(), new StringConstantBinding("Constant value")); t.bind(it.next(), new StringNodeBinding(source.at("/rootSourceString"))); t.bind(it.next(), new ArrayNodeBinding(source.at("/rootSourceArray/{i}/{i}/someSourceArray"))); t.bind(it.next(), new StringNodeBinding(source.at("/rootSourceArray/{i}/{i}/someSourceArray/{i}"))); // produce something JsonNode payload = new ObjectMapper().readTree(new File(SOURCE_PAYLOAD)); JsonNode result = t.apply(payload); ObjectMapper om = new ObjectMapper(); try { System.out.println("Original payload:"); System.out.println(om.writerWithDefaultPrettyPrinter().writeValueAsString(payload)); System.out.println("\nResulting payload:"); System.out.println(om.writerWithDefaultPrettyPrinter().writeValueAsString(result)); } catch (JsonProcessingException ex) { System.err.println("Oups: " + ex); } }
From source file:Main.java
public static void main(String[] args) { ArrayList aList = new ArrayList(); aList.add("1"); aList.add("2"); aList.add("3"); aList.add("4"); aList.add("java2 s .com"); System.out.println("ArrayList: "); System.out.println(aList);/*w w w . java2s . com*/ Iterator itr = aList.iterator(); String strElement = ""; while (itr.hasNext()) { strElement = (String) itr.next(); if (strElement.equals("2")) { itr.remove(); break; } } System.out.println("ArrayList after removal : "); System.out.println(aList); }
From source file:com.discursive.jccook.bean.BeanUtilExample.java
public static void main(String[] pArgs) { if (pArgs.length > 0 && pArgs[0] != null) { propName = pArgs[0];/*w w w. ja v a 2s.c o m*/ } System.out.println("Getting Property: " + propName); List books = createBooks(); Iterator i = books.iterator(); while (i.hasNext()) { Book book = (Book) i.next(); Object propVal = null; try { propVal = PropertyUtils.getProperty(book, propName); } catch (Exception e) { System.out.println("Error getting property: " + propName + ", from book: " + book.getName() + ", exception: " + e.getMessage()); } System.out.println("Property Value: " + propVal); } }
From source file:Employee.java
public static void main(String args[]) { LinkedList<Employee> phonelist = new LinkedList<Employee>(); phonelist.add(new Employee("A", "1")); phonelist.add(new Employee("B", "2")); phonelist.add(new Employee("C", "3")); Iterator<Employee> itr = phonelist.iterator(); Employee pe;//from w w w . j a v a2s. c o m while (itr.hasNext()) { pe = itr.next(); System.out.println(pe.name + ": " + pe.number); } ListIterator<Employee> litr = phonelist.listIterator(phonelist.size()); while (litr.hasPrevious()) { pe = litr.previous(); System.out.println(pe.name + ": " + pe.number); } }
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 w w .ja va 2 s .com*/ }
From source file:Person.java
public static void main(String args[]) { ArrayList<Person> names = new ArrayList<Person>(); names.add(new Person("E", "T")); names.add(new Person("A", "G")); names.add(new Person("B", "H")); names.add(new Person("C", "J")); Iterator iter1 = names.iterator(); while (iter1.hasNext()) { System.out.println(iter1.next()); }//from w w w . j ava 2s. c o m Collections.sort(names, new PersonComparator()); Iterator iter2 = names.iterator(); while (iter2.hasNext()) { System.out.println(iter2.next()); } }
From source file:Main.java
public static void main(String[] args) { // create a LinkedList LinkedList<String> list = new LinkedList<String>(); // add some elements list.add("Hello"); list.add("from java2s.com"); list.add("10"); // print the list System.out.println("LinkedList:" + list); // set Iterator at specified index Iterator x = list.listIterator(1); // print list with the iterator while (x.hasNext()) { System.out.println(x.next()); }/*from w ww. j a va 2 s .c o m*/ }
From source file:ArraySet.java
public static void main(String args[]) { String elements[] = { "A", "B", "C", "D", "E" }; Set set = new ArraySet(Arrays.asList(elements)); Iterator iter = set.iterator(); while (iter.hasNext()) { System.out.println(iter.next()); }/*from w ww. ja v a 2 s. co m*/ }