Example usage for java.util Set iterator

List of usage examples for java.util Set iterator

Introduction

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

Prototype

Iterator<E> iterator();

Source Link

Document

Returns an iterator over the elements in this set.

Usage

From source file:Main.java

public static String hashMapToString(Map<? extends Object, ? extends Object> map) {
    Set<?> entrySet = map.entrySet();
    Iterator<?> it = entrySet.iterator();
    Map.Entry<? extends Object, ? extends Object> entry = null;
    StringBuilder strbldr = new StringBuilder();
    strbldr.append("{ ");
    while (it.hasNext()) {
        entry = (Entry<? extends Object, ? extends Object>) it.next();
        strbldr.append(entry.getKey() + ":" + entry.getValue() + ", ");
    }//from w  w w.  j  a v  a2s.c  o m
    return new StringBuilder(strbldr.substring(0, strbldr.length() - 2)).append(" }").toString();
}

From source file:Main.java

public static String StringFromMap(Map<String, String> map) {
    StringBuilder sb = new StringBuilder();
    Set<String> set = map.keySet();

    for (Iterator iter = set.iterator(); iter.hasNext();) {
        String key = (String) iter.next();
        sb.append(key + "    " + map.get(key) + "\n");
    }// w w w .  j  ava 2s  .com

    return sb.toString();
}

From source file:Main.java

public static boolean containsMap(Map mainMap, Map keyMap) {
    boolean b = true;
    if (mainMap != null && keyMap != null) {
        Set set = keyMap.keySet();
        for (Iterator iter = set.iterator(); iter.hasNext();) {
            String key = (String) iter.next();
            String mainValue = (String) mainMap.get(key);
            String keyValue = (String) keyMap.get(key);
            if (!mainValue.equals(keyValue)) {
                b = false;//  w w w  .  j av a  2 s.c o  m
            }
        }
    } else {
        b = false;
    }
    return b;
}

From source file:Main.java

public static Map<String, String> bundleToMap(Bundle extras) {
    Map<String, String> map = new HashMap<String, String>();

    Set<String> ks = extras.keySet();
    Iterator<String> iterator = ks.iterator();
    while (iterator.hasNext()) {
        String key = iterator.next();
        map.put(key, extras.getString(key));
    }//from  w ww  .j a va2 s  .  c  o  m
    return map;
}

From source file:Main.java

public static void printMapBySet(Map map) {
    Set<String> ketSet = map.keySet();
    Iterator<String> iterator = ketSet.iterator();
    while (iterator.hasNext()) {
        String key = iterator.next();
        String value = (String) map.get(key);
        Log.i(TAG, "----key = " + key + ",value = " + value);
    }/* w  ww .  j a  v  a  2s. c om*/

}

From source file:Main.java

/**
 * Get key value of map in String/*  w w w.j a  v a2 s.  c o m*/
 * 
 * @version 1.0
 * @author pankajbharti
 */
@SuppressWarnings("rawtypes")
public static String getKeyValue(Map map) {
    StringBuilder str = new StringBuilder("");

    Set keySet = map.entrySet();

    Iterator itr = keySet.iterator();

    while (itr.hasNext()) {
        Map.Entry entry = (Map.Entry) itr.next();

        str.append(entry.getKey() + " : " + entry.getValue() + "\n" + "\t \t \t \t \t");
    }

    return str.toString();
}

From source file:Util.java

public static String dump(Map map) {
    if (map == null)
        return "null";

    StringBuffer buf = new StringBuffer().append('{');
    Set keys = map.keySet();
    Iterator iterator = keys.iterator();
    Object key;/*from w ww. java  2s .  c o m*/
    Object value;

    boolean first = true;
    while (iterator.hasNext()) {
        if (first)
            first = false;
        else
            buf.append(',');
        key = iterator.next();
        value = map.get(key);
        buf.append(key + "->" + value);
    }
    buf.append('}');
    return buf.toString();
}

From source file:Main.java

public static <V, T> void showMap(Map<V, T> map) {
    Set<Map.Entry<V, T>> set = map.entrySet();
    for (Iterator<Map.Entry<V, T>> it = set.iterator(); it.hasNext();) {
        Map.Entry<V, T> entry = it.next();
        System.out.println(entry.getKey() + "----->" + entry.getValue());
    }//from  w ww  . j a  v  a2 s.co m
}

From source file:Main.java

/**
 * Check whether map contains value/*w  ww.ja v a 2  s  .c o m*/
 *
 * @param map specified map
 * @return boolean value
 */
public static boolean isEmpty(Map map) {
    boolean isEmpty = true;
    if (map != null) {
        Set keySet = map.keySet();
        Iterator it = keySet.iterator();
        while (it.hasNext()) {
            if (map.get(it.next()) != null) {
                isEmpty = false;
                break;
            }
        }
    }
    return isEmpty;
}

From source file:Main.java

public static void dumpIntent(Intent i) {

    Bundle bundle = i.getExtras();//w w  w  .  jav a 2  s  .  c  o m
    if (bundle != null) {
        Set<String> keys = bundle.keySet();
        Iterator<String> it = keys.iterator();
        while (it.hasNext()) {
            String key = it.next();
        }
    }
}