List of usage examples for java.util List iterator
Iterator<E> iterator();
From source file:Main.java
public static void main(String[] args) throws Exception { System.setProperty("java.net.useSystemProxies", "true"); List l = ProxySelector.getDefault().select(new URI("http://www.yahoo.com/")); for (Iterator iter = l.iterator(); iter.hasNext();) { Proxy proxy = (Proxy) iter.next(); System.out.println("proxy hostname : " + proxy.type()); InetSocketAddress addr = (InetSocketAddress) proxy.address(); if (addr == null) { System.out.println("No Proxy"); } else {//from w w w . java 2 s. c o m System.out.println("proxy hostname : " + addr.getHostName()); System.out.println("proxy port : " + addr.getPort()); } } }
From source file:Main.java
public static void main(String[] argv) { List collection = new ArrayList(); // For a set or list for (Iterator it = collection.iterator(); it.hasNext();) { Object element = it.next(); }//from w w w.jav a2 s . co m Map map = new HashMap(); // For keys of a map for (Iterator it = map.keySet().iterator(); it.hasNext();) { Object key = it.next(); } // For values of a map for (Iterator it = map.values().iterator(); it.hasNext();) { Object value = it.next(); } // For both the keys and values of a map for (Iterator it = map.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); Object key = entry.getKey(); Object value = entry.getValue(); } }
From source file:MainClass.java
public static void main(String[] args) { List cats = new ArrayList(); for (int i = 0; i < 7; i++) cats.add(new Cat(i)); Iterator e = cats.iterator(); while (e.hasNext()) ((Cat) e.next()).id();/*from ww w .ja va 2s. c om*/ }
From source file:Main.java
public static void main(String[] args) { // Create a list of strings List<String> names = new ArrayList<>(); names.add("A"); names.add("B"); names.add("C"); Iterator<String> nameIterator = names.iterator(); nameIterator.forEachRemaining(System.out::println); }
From source file:com.pureinfo.srm.reports.cmd.data.FeeByCollege.java
public static void main(String[] args) throws PureException { List l = new FeeByCollege().getListDatas(); for (Iterator iter = l.iterator(); iter.hasNext();) { DolphinObject obj = (DolphinObject) iter.next(); obj.update();/*w w w. j a v a 2s .co m*/ System.out .println("{\"" + obj.getProperty("NAME") + "\",new Double(" + obj.getProperty("VALUE") + ")},"); } }
From source file:com.pureinfo.srm.reports.cmd.data.OutlayByCollege.java
public static void main(String[] args) throws PureException { List l = new OutlayByCollege().getListDatas(); for (Iterator iter = l.iterator(); iter.hasNext();) { DolphinObject obj = (DolphinObject) iter.next(); obj.update();/* ww w .jav a 2 s .c o m*/ System.out .println("{\"" + obj.getProperty("NAME") + "\",new Double(" + obj.getProperty("VALUE") + ")},"); } }
From source file:com.pureinfo.srm.reports.cmd.data.PrjNumberByCollege.java
public static void main(String[] args) throws PureException { List l = new PrjNumberByCollege().getListDatas(); for (Iterator iter = l.iterator(); iter.hasNext();) { DolphinObject obj = (DolphinObject) iter.next(); obj.update();/*from ww w . java 2 s . c o m*/ System.out .println("{\"" + obj.getProperty("NAME") + "\",new Double(" + obj.getProperty("VALUE") + ")},"); } }
From source file:Main.java
public static void main(String[] args) { // Create a list of strings List<String> names = new ArrayList<>(); names.add("A"); names.add("B"); names.add("C"); Iterator<String> nameIterator = names.iterator(); // Iterate over all elements in the list while (nameIterator.hasNext()) { // Get the next element from the list String name = nameIterator.next(); System.out.println(name); nameIterator.remove();/*from w ww . j ava 2 s . c o m*/ } System.out.println(names); }
From source file:Main.java
public static void main(String[] args) { Map<String, Student> map = new HashMap<>(); map.put("s1", new Student(5, "A")); map.put("s2", new Student(4, "B")); map.put("s3", new Student(10, "C")); map.put("s4", new Student(2, "D")); Collection<Student> students = map.values(); List<Student> list = new ArrayList<>(students); Collections.sort(list, new MyComparator()); for (Iterator<Student> it = list.iterator(); it.hasNext();) { Student stdn = (Student) it.next(); System.out.println("Student id : " + stdn.id); System.out.println("Student Name : " + stdn.name); }//from w w w. j ava 2 s.c o m }
From source file:MyComparator.java
public static void main(String[] args) { TreeMap tm = new TreeMap(); tm.put(1, new Double(344.34)); tm.put(0, new Double(123.22)); tm.put(4, new Double(138.00)); tm.put(2, new Double(919.22)); tm.put(3, new Double(-119.08)); List<Map.Entry> valueList = new ArrayList(tm.entrySet()); Collections.sort(valueList, new MyComparator()); Iterator<Map.Entry> iterator = valueList.iterator(); while (iterator.hasNext()) { Map.Entry entry = iterator.next(); System.out.println("Value: " + entry.getValue()); }/*from www . j a v a 2s. co m*/ }