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:Main.java

public static void removeDuplicateWithOrder(List arlList) {
    Set set = new HashSet();
    List newList = new ArrayList();
    for (Iterator iter = arlList.iterator(); iter.hasNext();) {
        Object element = iter.next();
        if (set.add(element))
            newList.add(element);/* w  w  w  . j a v a2  s  . c o m*/
    }
    arlList.clear();
    arlList.addAll(newList);
}

From source file:Main.java

public static void startApkActivity(final Context ctx, String packageName) {
    PackageManager pm = ctx.getPackageManager();
    PackageInfo pi;/*from   w  ww.  ja  v  a 2 s.  co  m*/
    try {
        pi = pm.getPackageInfo(packageName, 0);
        Intent intent = new Intent(Intent.ACTION_MAIN, null);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setPackage(pi.packageName);

        List<ResolveInfo> apps = pm.queryIntentActivities(intent, 0);

        ResolveInfo ri = apps.iterator().next();
        if (ri != null) {
            String className = ri.activityInfo.name;
            intent.setComponent(new ComponentName(packageName, className));
            ctx.startActivity(intent);
        }
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static String buildValuesString(List<Object> values) {
    StringBuilder sb = new StringBuilder();
    Iterator<Object> valueIt = values.iterator();
    while (valueIt.hasNext()) {
        sb.append(valueIt.next());//from w w w . java  2 s .  c o  m
        if (valueIt.hasNext()) {
            sb.append(";");
        }
    }
    return sb.toString();
}

From source file:Main.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static List removeDuplicateWithOrder(List list) {
    Set set = new HashSet();
    List newList = new ArrayList();
    for (Iterator iter = list.iterator(); iter.hasNext();) {
        Object element = iter.next();
        if (set.add(element))
            newList.add(element);/*from ww  w  .j  a  va 2s . c o m*/
    }
    return newList;
}

From source file:Main.java

/**
 * Makes an intersection betwwen both of the given lists.<br/>
 * The result contains unique values./*  ww  w  . j a  v  a 2s.  com*/
 * @param list1 the first list.
 * @param list2 the second list.
 * @param <T>
 * @return the intersection between the two lists.
 */
public static <T> List<T> intersection(List<T> list1, List<T> list2) {
    List<T> list = new ArrayList<T>(new LinkedHashSet<T>(list1));
    Iterator<T> iterator = list.iterator();
    while (iterator.hasNext()) {
        if (!list2.contains(iterator.next())) {
            iterator.remove();
        }
    }
    return list;
}

From source file:Main.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static List removeDuplicate(List list) {
    Set set = new HashSet();
    List newList = new ArrayList();
    for (Iterator iter = list.iterator(); iter.hasNext();) {
        Object element = iter.next();
        if (set.add(element))
            newList.add(element);//  w  ww .  ja  v  a  2 s. c  om
    }
    //         list.addAll(newList);
    return newList;
}

From source file:Main.java

public static List getChildElementValues(Element p_rootElement, String p_elementName) {
    List result = new ArrayList();
    List elems = getChildElements(p_rootElement, p_elementName);
    for (Iterator itor = elems.iterator(); itor.hasNext();) {
        Element elem = (Element) itor.next();
        result.add(getElementValue(elem));
    }/*from  ww  w .  ja  va 2s .c om*/
    return result;
}

From source file:Main.java

public static List getDirectChildElementValues(Element p_rootElement, String p_elementName) {
    List result = new ArrayList();
    List elems = getChildElements(p_rootElement, p_elementName);
    for (Iterator itor = elems.iterator(); itor.hasNext();) {
        Element elem = (Element) itor.next();
        result.add(getElementValue(elem));
    }//from   ww w . j  a v  a 2  s.co m
    return result;
}

From source file:Main.java

/**
 * Joins the {@link String} representation of elements of a given list,
 * dividing with a separator./*from  w  w w  .j av a  2  s .  c om*/
 * 
 * @param input
 *            - the {@link List} of elements to join.
 * @param separator
 *            - the separator to place between elements
 * @return - the joined {@link String}
 */
public static <E extends Object> String join(List<E> input, String separator) {
    StringBuilder result = new StringBuilder();
    Iterator<E> it = input.iterator();

    while (it.hasNext()) {
        result.append(it.next());
        if (separator != null && it.hasNext()) {
            result.append(separator);
        }
    }

    return result.toString();
}

From source file:Main.java

public static Element getChild(Element parentEl, String name) {

    Element child = null;//from   w  ww. j av  a 2  s  . c om
    List children = getChildren(parentEl, name);
    if (children.size() > 0) {
        child = (Element) children.iterator().next();
    }
    return child;
}