List of usage examples for java.util Iterator hasNext
boolean hasNext();
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(""); }/* w w w . j a v a 2 s . c o m*/ }
From source file:Main.java
@SuppressWarnings("rawtypes") public static Map<Integer, String> swapStrKeysAndIntValues(Map<String, Integer> hm) { HashMap<Integer, String> nhm = new HashMap<Integer, String>(); Set<?> s = hm.entrySet(); Iterator<?> it = s.iterator(); while (it.hasNext()) { Map.Entry m = (Map.Entry) it.next(); nhm.put((Integer) m.getValue(), (String) m.getKey()); }//from w w w .j av a 2 s. c o m return nhm; }
From source file:Main.java
@SuppressWarnings("rawtypes") public static Map<String, Integer> swapIntKeysAndStrValues(Map<Integer, String> hm) { HashMap<String, Integer> nhm = new HashMap<String, Integer>(); Set<?> s = hm.entrySet(); Iterator<?> it = s.iterator(); while (it.hasNext()) { Map.Entry m = (Map.Entry) it.next(); nhm.put((String) m.getValue(), (Integer) m.getKey()); }/*from w w w . j a v a2 s . c o m*/ return nhm; }
From source file:Main.java
public static void display(Collection collection) { Iterator iterator = collection.iterator(); while (iterator.hasNext()) { System.out.print(iterator.next() + " "); }// w w w. j ava 2 s . c o m System.out.println(); }
From source file:Main.java
@SuppressWarnings("rawtypes") public static Map<String, String> swapStrKeysAndStrValues(Map<String, ?> hm) { HashMap<String, String> nhm = new HashMap<String, String>(); Set<?> s = hm.entrySet(); Iterator<?> it = s.iterator(); while (it.hasNext()) { Map.Entry m = (Map.Entry) it.next(); nhm.put((String) m.getValue(), (String) m.getKey()); }/*from www . j av a 2s. co m*/ return nhm; }
From source file:com.apextom.util.CollectionUtil.java
/** * ? null .// ww w .j a v a2s . c o m * * @param list */ public static void removeNull(Collection<Object> list) { if (list == null || list.size() == 0) { return; } Iterator<Object> iter = list.iterator(); while (iter.hasNext()) { if (iter.next() == null) { iter.remove(); } } }
From source file:Main.java
public static List<String> removeIgnoreCase(List<String> l, String s) { Iterator<String> iter = l.iterator(); while (iter.hasNext()) { if (iter.next().equalsIgnoreCase(s)) { iter.remove();//from w w w . j a v a 2s .c om break; } } return l; }
From source file:Main.java
public static void printMap(Map map) { Iterator iter = map.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); System.out.println(entry.getKey() + ": " + entry.getValue()); }/* w w w. ja v a 2 s.c o m*/ }
From source file:Main.java
public static <T> List<T> intersection(Collection<T> a, Collection<T> b) { ArrayList list = new ArrayList(); Iterator i$ = a.iterator(); while (i$.hasNext()) { Object element = i$.next(); if (b.contains(element)) { list.add(element);/*from w w w .j a v a 2 s . c o m*/ } } return list; }
From source file:Main.java
public static <E> E getFirst(Collection<E> collection, E defaultValue) { Iterator<E> iterator = collection.iterator(); return iterator.hasNext() ? iterator.next() : defaultValue; }