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 long[] convertListLongs(List<Long> longs) {
    long[] ret = new long[longs.size()];
    Iterator<Long> iterator = longs.iterator();
    for (int i = 0; i < ret.length; i++) {
        ret[i] = iterator.next();/*www  . j  av a2 s .  c o  m*/
    }
    return ret;
}

From source file:Main.java

public static <X, Y> Map<X, Y> map(List<X> keys, Iterable<Y> values) {
    Map<X, Y> ret = new HashMap<X, Y>();
    Iterator<X> ks = keys.iterator();
    Iterator<Y> vs = values.iterator();
    while (ks.hasNext()) {
        ret.put(ks.next(), vs.next());/*from  www. ja  v a  2  s  .c om*/
    }
    if (vs.hasNext()) {
        throw new RuntimeException("values is greater than keys");
    }
    return ret;
}

From source file:Main.java

/** Write all Identifiables that we contain to os.  The total
 * length must be written before this method is called.
 *//*from   w  w w .  j a  v  a2 s.  c  o m*/
public static void writeIdentifiableSequence(List container, OutputStream os) {
    os.write_long(container.size());
    Iterator iter = container.iterator();
    while (iter.hasNext()) {
        Identifiable obj = (Identifiable) (iter.next());
        os.write_long(obj.getId());
        obj.write(os);
    }
}

From source file:edu.harvard.hul.ois.fits.tools.utils.XsltTransformMap.java

public static Hashtable getMap(String config) throws FitsConfigurationException {
    Hashtable mappings = new Hashtable();
    XMLConfiguration conf = null;/*ww  w . j  a  v a 2 s . com*/
    try {
        conf = new XMLConfiguration(config);
    } catch (ConfigurationException e) {
        throw new FitsConfigurationException("Error reading " + config + "fits.xml", e);
    }

    List fields = conf.configurationsAt("map");
    for (Iterator it = fields.iterator(); it.hasNext();) {
        HierarchicalConfiguration sub = (HierarchicalConfiguration) it.next();
        // sub contains now all data about a single field
        String format = sub.getString("[@format]");
        String transform = sub.getString("[@transform]");
        mappings.put(format, transform);
    }
    return mappings;
}

From source file:Main.java

public static int[] integerListToIntArray(List<Integer> integers) {
    int[] ret = new int[integers.size()];
    Iterator<Integer> iterator = integers.iterator();

    for (int i = 0; i < ret.length; i++) {
        ret[i] = iterator.next().intValue();
    }//from   www .j a v  a 2 s . c o m

    return ret;
}

From source file:Main.java

public static <T> List<T> removeDuplicate(List<T> 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 w  w w  .  ja v a 2 s  .  com*/
    }
    return newList;
}

From source file:Main.java

public static void deleteDuplicate(List<Integer> list) {
    List<Integer> tempList = new ArrayList<Integer>();

    Iterator<Integer> iter = list.iterator();
    while (iter.hasNext()) {
        Integer current = iter.next();
        if (tempList.contains(current)) {
            iter.remove();/*from w  w  w .j a v a2 s  .c  o m*/
        } else {
            tempList.add(current);
        }
    }
}

From source file:Main.java

public static final long[] listLong2longarray(List<Long> list) {
    final long[] dst = new long[list.size()];
    int i = 0;/*  ww w. j  ava2  s.c  o  m*/
    for (Iterator<Long> iter = list.iterator(); iter.hasNext();) {
        dst[i++] = (iter.next()).longValue();
    }
    return dst;
}

From source file:Main.java

public static void startApkActivity(final Context ctx, String packageName) {
    PackageManager pm = ctx.getPackageManager();
    PackageInfo pi;// www .  j  av 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 (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static int[] convertListIntegers(List<Integer> integers) {
    int[] ret = new int[integers.size()];
    Iterator<Integer> iterator = integers.iterator();
    for (int i = 0; i < ret.length; i++) {
        ret[i] = iterator.next();//from  ww w .j a va2  s. c  o  m
    }
    return ret;
}