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:fll.web.UploadProcessor.java

/**
 * Processes <code>request</code> as a file upload and puts the results back
 * in the <code>request</code> object. Each parameter that is a file upload
 * has a value of type {@link FileItem}. Other parameters have values of type
 * {@link String}.//w w w. j  av  a2s  .c  o  m
 * 
 * @param request
 */
public static void processUpload(final HttpServletRequest request) throws FileUploadException {
    // Parse the request
    final List<?> items = UPLOAD.parseRequest(request);
    final Iterator<?> iter = items.iterator();
    while (iter.hasNext()) {
        final FileItem item = (FileItem) iter.next();
        if (item.isFormField()) {
            request.setAttribute(item.getFieldName(), item.getString());
        } else {
            request.setAttribute(item.getFieldName(), item);
        }
    }
}

From source file:Main.java

static Iterator getAlgNames() {
    Enumeration e = algorithms.keys();
    List l = new ArrayList();

    while (e.hasMoreElements()) {
        l.add(e.nextElement());//from   w w w . j a va  2  s . com
    }

    return l.iterator();
}

From source file:webservices.simple_jaxb.UnmarshalRead.java

public static void displayItems(Items items) {
    // the items object contains a List of primer.po.ItemType objects
    List itemTypeList = items.getItem();

    // iterate over List
    for (Iterator iter = itemTypeList.iterator(); iter.hasNext();) {
        Items.Item item = (Items.Item) iter.next();
        System.out.println("\t" + item.getQuantity() + " copies of \"" + item.getProductName() + "\"");
    }/*from  w  ww.j  av a  2 s  .  com*/
}

From source file:Main.java

/**
 *///from  w w  w  .j  av  a 2 s . c o m
public static String[] getTextElements(List<Element> elements) throws Exception {
    ArrayList<String> list = new ArrayList<String>();
    Iterator<Element> iter = elements.iterator();
    while (iter.hasNext()) {
        String s = iter.next().getFirstChild().getTextContent();
        list.add(s);
    }
    return list.toArray(new String[0]);
}

From source file:com.google.ie.common.email.EmailManager.java

/**
 * Convert list of Strings to one comma separated String.
 * //w  ww  .  ja  va  2  s.  c  o m
 * @param otherInfoList list of strings
 * @return comma separated string
 */
public static String getStringFromList(List<String> otherInfoList) {
    Iterator<String> iterator = otherInfoList.iterator();
    StringBuilder stringBuilder = new StringBuilder();
    while (iterator.hasNext()) {
        String info = iterator.next();
        stringBuilder.append(info);
        if (iterator.hasNext()) {
            stringBuilder.append(COMMA);
        }

    }
    return stringBuilder.toString();
}

From source file:Main.java

public final static String join(List<String> command, char c) {
    StringBuilder sb = new StringBuilder();
    for (Iterator<String> it = command.iterator(); it.hasNext();) {
        sb.append(it.next());// w  w  w  .  j av a2 s.co m
        if (it.hasNext())
            sb.append(c);
    }
    return sb.toString();
}

From source file:Main.java

public static String join(List list, String separator) {
    StringBuilder sb = new StringBuilder();
    String ele;//from  w w  w  . ja v a2  s.  com
    for (Iterator i$ = list.iterator(); i$.hasNext(); sb.append(ele)) {
        ele = (String) i$.next();
        if (sb.length() > 0)
            sb.append(separator);
    }

    return sb.toString();
}

From source file:Main.java

/**
 * Converts a List with org.w3c.dom.Element objects to an Array
 * with org.w3c.dom.Element objects.//w w  w  .  java2s. c om
 * @param list List containing org.w3c.dom.Element objects
 * @return Element[] Array with org.w3c.dom.Element objects
 */
public static Element[] asElementArray(List list) {

    Element[] elements = new Element[list.size()];

    int i = 0;
    Iterator detailIter = list.iterator();
    while (detailIter.hasNext()) {
        elements[i++] = (Element) detailIter.next();
    }

    return elements;
}

From source file:Main.java

public static boolean isServiceRunning(Context ctx, String className) {
    boolean isRunning = false;
    ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> servicesList = activityManager.getRunningServices(Integer.MAX_VALUE);
    Iterator<RunningServiceInfo> l = servicesList.iterator();
    while (l.hasNext()) {
        RunningServiceInfo si = (RunningServiceInfo) l.next();
        if (className.equals(si.service.getClassName())) {
            isRunning = true;//from ww w .  ja  va 2 s  .com
        }
    }
    return isRunning;
}

From source file:Main.java

public static <T> List<T> copyWithoutDublicates(List<T> l) {
    final List<T> result = new ArrayList<T>();
    final Set<T> set = new HashSet<T>();
    for (Iterator<T> it = l.iterator(); it.hasNext();) {
        final T t = it.next();
        if (set.add(t)) {
            result.add(t);/*w  w  w  .  ja v a 2  s  .c  om*/
        }
    }
    return result;
}