Example usage for java.util List iterator

List of usage examples for java.util List iterator

Introduction

In this page you can find the example usage for java.util List iterator.

Prototype

Iterator<E> iterator();

Source Link

Document

Returns an iterator over the elements in this list in proper sequence.

Usage

From source file:JDOMTest.java

public static void showBooks(Element root) {
    List books = root.getChildren("book");
    for (Iterator i = books.iterator(); i.hasNext();) {
        Element book = (Element) i.next();
        System.out.println("Book: " + book.getAttributeValue("category") + ", " + book.getChildTextTrim("title")
                + ", " + book.getChildTextTrim("author") + ", " + book.getChildTextTrim("price"));
    }/*from ww w  .  j a  v a  2 s  .c  o m*/
}

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();/* w  w  w. ja  v  a  2  s  .c  om*/
            break;
        }
    }
    return l;
}

From source file:Main.java

public static void showList(List<? extends Object> lst) {
    Iterator<? extends Object> it = lst.iterator();
    while (it.hasNext()) {
        System.out.println(it.next());
    }/*from   w  ww  . ja v a2s.  c  o m*/
}

From source file:Main.java

public static void removeNullValues(List<?> list) {

    Iterator<?> iterator = list.iterator();

    while (iterator.hasNext()) {

        Object value = iterator.next();

        if (value == null) {

            iterator.remove();//w  w w. j  av  a 2  s . co m
        }
    }
}

From source file:StringBuilderTester.java

public static String appendItems(List list) {
    StringBuilder b = new StringBuilder();

    for (Iterator i = list.iterator(); i.hasNext();) {
        b.append(i.next()).append(" ");
    }//from  w  ww .  ja  va 2  s  .c om

    return b.toString();
}

From source file:Main.java

public static boolean containsSize(List<Size> sizes, Size size) {
    for (Iterator<Size> iterator = sizes.iterator(); iterator.hasNext();) {
        Size currSize = iterator.next();
        if (currSize.width == size.width && currSize.height == size.height) {
            return true;
        }//www .j  av  a 2s  .  c o  m
    }
    return false;
}

From source file:Main.java

public static String getListNextElement(String pre, List list) {
    String next = null;/* w w  w .  j  a v a2  s  . c  o  m*/
    for (Iterator it = list.iterator(); it.hasNext();) {
        String obj = (String) it.next();
        if (obj.equals(pre) && it.hasNext()) {
            next = (String) it.next();
            break;
        }
    }
    return next;
}

From source file:Main.java

/**
 * Safety add element included in source collection to target collection
 * if target has already had element that is included in source collection,
 * it doesn't add element to target/* w w w . j a v  a  2  s.  c  o m*/
 *
 * @param src    source collection
 * @param target target collection
 */
public static void safetyMergeCollection(List src, List target) {
    for (Iterator it = src.iterator(); it.hasNext();) {
        Object data = it.next();
        if (!target.contains(data)) {
            target.add(data);
        }
    }
}

From source file:Main.java

/**
 * Returns true iff l1 is a sublist of l (i.e., every member of l1 is in l,
 * and for every e1 < e2 in l1, there is an e1 < e2 occurrence in l).
 *//*w w  w. j  a  v  a  2 s .  c  o m*/
public static <T> boolean isSubList(List<T> l1, List<? super T> l) {
    Iterator<? super T> it = l.iterator();
    for (T o1 : l1) {
        if (!it.hasNext()) {
            return false;
        }
        Object o = it.next();
        while ((o == null && !(o1 == null)) || (o != null && !o.equals(o1))) {
            if (!it.hasNext()) {
                return false;
            }
            o = it.next();
        }
    }
    return true;
}

From source file:Main.java

public static boolean containsIgnoreCase(List<String> l, String s) {
    Iterator<String> it = l.iterator();
    while (it.hasNext()) {
        if (it.next().equalsIgnoreCase(s))
            return true;
    }//from ww w . j  a  va  2 s  .co m
    return false;
}