List of usage examples for java.util List iterator
Iterator<E> iterator();
From source file:Main.java
public static double getSumValue(HashMap<String, Double> map) { Double count = 0.0D;/*from w w w . ja v a2 s . com*/ List list = new LinkedList(map.entrySet()); for (Iterator it = list.iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); count += map.get(entry.getKey()); } return count; }
From source file:Main.java
public static void writeToWriter(List l, Writer out) throws IOException { writeToWriter(l.iterator(), out); }
From source file:Main.java
public static void printParameter(NetworkInterface ni) throws SocketException { System.out.println(" Name = " + ni.getName()); System.out.println(" Display Name = " + ni.getDisplayName()); System.out.println(" Is up = " + ni.isUp()); System.out.println(" Support multicast = " + ni.supportsMulticast()); System.out.println(" Is loopback = " + ni.isLoopback()); System.out.println(" Is virtual = " + ni.isVirtual()); System.out.println(" Is point to point = " + ni.isPointToPoint()); System.out.println(" Hardware address = " + ni.getHardwareAddress()); System.out.println(" MTU = " + ni.getMTU()); System.out.println("\nList of Interface Addresses:"); List<InterfaceAddress> list = ni.getInterfaceAddresses(); Iterator<InterfaceAddress> it = list.iterator(); while (it.hasNext()) { InterfaceAddress ia = it.next(); System.out.println(" Address = " + ia.getAddress()); System.out.println(" Broadcast = " + ia.getBroadcast()); System.out.println(" Network prefix length = " + ia.getNetworkPrefixLength()); System.out.println(""); }/*from w ww . j a va 2 s .c o m*/ }
From source file:Main.java
/** * Finds the first object in the heterogeneous list that is an instance of * the given class, removes it from the list, and returns it. * If there is not object in the list of the given type the list is left * unmodified and null is returned./*from w w w . java 2s. c o m*/ * * @throws NullPointerException if list or clazz is null * @throws UnsupportedOperationException if the list's Iterator does not support the remove() * method */ @SuppressWarnings("unchecked") public static <T> T findFirstAndRemove(List<?> list, Class<T> clazz) { for (Iterator<?> iter = list.iterator(); iter.hasNext();) { Object o = iter.next(); if (clazz.isInstance(o)) { iter.remove(); return (T) o; // safe } } return null; }
From source file:Main.java
public static Optional<XMLEvent> getStartElement(List<XMLEvent> events, String elementName) { Iterator<XMLEvent> iterator = events.iterator(); while (iterator.hasNext()) { XMLEvent event = iterator.next(); if (event.isStartElement() && event.asStartElement().getName().getLocalPart().equals(elementName)) return Optional.of(event); }/* w w w . j ava 2 s. c om*/ return Optional.empty(); }
From source file:Main.java
public static String ListToString(String glue, List<Integer> myList) { String newString = ""; for (Iterator<Integer> it = myList.iterator(); it.hasNext();) { newString += it.next();/*from www. j av a2 s .c o m*/ if (it.hasNext()) { newString += ", "; } } return newString; }
From source file:Main.java
/** * Converts a list of string values to a map with the string value as both * key and value/*from ww w. j a v a2s . c om*/ * * @param stringValues * @return a Map */ public static Map toMap(List stringValues) { Map map = new HashMap(); for (Iterator iter = stringValues.iterator(); iter.hasNext();) { String value = (String) iter.next(); map.put(value, value); } return map; }
From source file:Main.java
private static List getMainProcessNames(List list) { ArrayList arraylist = new ArrayList(); Iterator iterator = list.iterator(); do {/*from w w w .ja v a 2s . c o m*/ if (!iterator.hasNext()) break; String s = (String) iterator.next(); int i = s.indexOf(":"); if (i > 0) arraylist.add(s.substring(0, i)); } while (true); return arraylist; }
From source file:Main.java
public static String getClasspathString(List<File> c) { StringBuilder sb = new StringBuilder(); Iterator<File> i = c.iterator(); if (i.hasNext()) { sb.append(i.next().getAbsolutePath()); while (i.hasNext()) { sb.append(File.pathSeparatorChar); sb.append(i.next().getAbsolutePath()); }//from www. j a va2s. c o m } return sb.toString(); }
From source file:Main.java
public static Optional<Characters> getCharacterEventOfElement(List<XMLEvent> events, String elementName) { Iterator<XMLEvent> iterator = events.iterator(); while (iterator.hasNext()) { XMLEvent event = iterator.next(); if (event.isStartElement() && event.asStartElement().getName().getLocalPart().equals(elementName)) { XMLEvent nextEvent = iterator.next(); if (nextEvent.isCharacters()) return Optional.of(nextEvent.asCharacters()); }/*w w w . ja va 2 s.com*/ } return Optional.empty(); }