Example usage for java.util Iterator hasNext

List of usage examples for java.util Iterator hasNext

Introduction

In this page you can find the example usage for java.util Iterator hasNext.

Prototype

boolean hasNext();

Source Link

Document

Returns true if the iteration has more elements.

Usage

From source file:Main.java

public static void writeToWriter(Iterator it, Writer out) throws IOException {
    while (it.hasNext()) {
        out.write(it.next().toString());
        out.write(newLine);//  w w w. j  av  a 2  s  .  com
    }
    out.flush();
}

From source file:Main.java

public static void freeBitmapMap(Map map) {
    Iterator iterator = map.entrySet().iterator();
    do {/*from  w  w w  . ja v  a 2 s .co  m*/
        if (!iterator.hasNext())
            break;
        Bitmap bitmap = (Bitmap) ((java.util.Map.Entry) iterator.next()).getValue();
        if (bitmap != null)
            bitmap.recycle();
    } while (true);
    map.clear();
}

From source file:Main.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public static void UpperCaseItems(Collection collection) {

    //Basic iterator ... cannot modify collection using this method.
    Iterator iterator = collection.iterator();
    while (iterator.hasNext()) {
        Object object = iterator.next();
        if (object instanceof String) {
            System.out.println(((String) object).toUpperCase());
            //object = ((String) object).toUpperCase();  doesn't actually change the underlying object.
        }/*w  w w.ja  v a  2s .c om*/
    }

    //old school for loop ... can modify collection. This is not a structural change to the collection, just a change to the members. Structural collection changes in a loop is not recommended.
    if (collection instanceof ArrayList) {
        for (int i = 0; i < collection.size(); i++) {
            Object object = ((ArrayList) collection).get(i);
            String item = ((String) object);
            ((ArrayList) collection).set(i, item.toUpperCase());
        }
    }
}

From source file:Main.java

private static void frequenceyCount(String input) {
    Map<Character, Integer> hashCount = new HashMap<>();
    Character c;/* w  w  w.ja  v a 2s  .  c om*/
    for (int i = 0; i < input.length(); i++) {
        c = input.charAt(i);
        if (hashCount.get(c) != null) {
            hashCount.put(c, hashCount.get(c) + 1);
        } else {
            hashCount.put(c, 1);
        }
    }
    Iterator it = hashCount.entrySet().iterator();
    System.out.println("char : frequency");
    while (it.hasNext()) {
        Map.Entry pairs = (Map.Entry) it.next();
        System.out.println(pairs.getKey() + " : " + pairs.getValue());
        it.remove();
    }
}

From source file:Main.java

public static ArrayList<Integer> filterPoint(ArrayList<Integer> timePoints) {
    int lastPeriod = -1;
    logInConsole(timePoints);//  ww w. j  a  v a 2 s.c om
    Iterator<Integer> it = timePoints.iterator();
    while (it.hasNext()) {
        int tmp = it.next();
        if (lastPeriod != -1 && tmp - lastPeriod < MIN_PERIOD) {
            it.remove();
        } else {
            lastPeriod = tmp;
        }
    }
    logInConsole(timePoints);
    return timePoints;
}

From source file:Main.java

public static String convert2XML_(Map<String, String> params) {
    StringBuffer sb = new StringBuffer("<xml>");
    try {/*from  ww w. j ava 2s  .com*/
        Iterator it = params.entrySet().iterator();
        while (it.hasNext()) {
            Entry entry = (Entry) it.next();
            sb.append("<![CDATA[" + entry.getValue() + "]]");
            sb.append(entry.getValue());
            sb.append("</" + entry.getKey() + ">");
        }
        sb.append("<CreateTime>").append(new Date().getTime()).append("</CreateTime>");
        sb.append("</xml>");

    } catch (Exception e) {
        e.printStackTrace();
    }
    return sb.toString();
}

From source file:Main.java

public static float[] asFloatArray(Collection<Float> collection) {
    float[] array = new float[collection.size()];
    Iterator<Float> iterator = collection.iterator();
    int i = 0;//  w  w  w  . j a  va 2 s.  c  om
    while (iterator.hasNext()) {
        array[i++] = iterator.next();
    }
    return array;
}

From source file:Main.java

public static boolean isNullOrEmpty(final Iterator<?> iterator) {
    return (iterator == null) || (!iterator.hasNext());
}

From source file:Main.java

public static <T extends Object> List<T> map2list(Map<String, T> maps) {
    List<T> list = new ArrayList<T>();
    Iterator<Entry<String, T>> iterator = maps.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<String, T> entry = iterator.next();
        list.add(entry.getValue());/*  w  w w  .  jav a 2 s  .c o m*/
    }
    return list;
}