List of usage examples for java.util Set iterator
Iterator<E> iterator();
From source file:Main.java
private static void organizeAndStart(Context context, Class<?> classes, Map<String, String> paramMap) { intent = new Intent(context, classes); if (null != paramMap) { Set<String> set = paramMap.keySet(); for (Iterator<String> iterator = set.iterator(); iterator.hasNext();) { String key = iterator.next(); intent.putExtra(key, paramMap.get(key)); }//from w w w . j a v a2s . c om } intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); context.startActivity(intent); }
From source file:Main.java
public static ArrayList<String> getHashMap(HashMap<String, String> hm) { ArrayList<String> a = new ArrayList<String>(); Set<Map.Entry<String, String>> s = hm.entrySet(); Iterator<Map.Entry<String, String>> it = s.iterator(); while (it.hasNext()) { Map.Entry<String, String> m = (Map.Entry<String, String>) it.next(); a.add(m.getKey() + "\t" + m.getValue()); }//from w ww .j av a 2 s . co m return a; }
From source file:Main.java
public static ArrayList<String> getHashMap2(HashMap<String, Integer> hm) { ArrayList<String> a = new ArrayList<String>(); Set<Map.Entry<String, Integer>> s = hm.entrySet(); Iterator<Map.Entry<String, Integer>> it = s.iterator(); while (it.hasNext()) { Map.Entry<String, Integer> m = (Map.Entry<String, Integer>) it.next(); a.add(m.getKey() + "\t" + m.getValue()); }/* ww w . j a v a 2 s .com*/ return a; }
From source file:Main.java
public static Vector setToVector(Set set) { Vector setVector = new Vector(); if (set != null) { for (Iterator i = set.iterator(); i.hasNext();) { setVector.add(i.next());/* w w w .j av a 2 s . c om*/ } } return setVector; }
From source file:Main.java
/** * HashMap Operations/* w w w .ja va 2s. c o m*/ * */ public static void printHash(HashMap<String, Integer> hashMap) { System.out.println("Print HashMap"); Set<Map.Entry<String, Integer>> s = hashMap.entrySet(); Iterator<Map.Entry<String, Integer>> it = s.iterator(); while (it.hasNext()) { Map.Entry<String, Integer> m = (Map.Entry<String, Integer>) it.next(); System.out.println(m.getKey() + "\t" + m.getValue()); } }
From source file:Main.java
public static void hashMapToXML222(String xmlFile, String xpath, HashMap hashmap) { try {//from w ww. ja v a 2 s .co m DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.newDocument(); Element rootNode = document.createElement(xpath); document.appendChild(rootNode); Set set = hashmap.entrySet(); Iterator i = set.iterator(); while (i.hasNext()) { Map.Entry me = (Map.Entry) i.next(); Element em = document.createElement(me.getKey().toString()); em.appendChild(document.createTextNode(me.getValue().toString())); rootNode.appendChild(em); // System.out.println("write " + // me.getKey().toString() + "=" // + me.getValue().toString()); } TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(document); FileOutputStream fo = new FileOutputStream(xmlFile); StreamResult result = new StreamResult(fo); transformer.transform(source, result); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static <K, V> List<K> getKeyListByValues(Map<K, V> map, V[] values) { if ((values == null) || (values.length == 0)) { return null; }/*from www . j ava 2s. com*/ List<K> keyList = new ArrayList<K>(map.size()); Set<Map.Entry<K, V>> entrySet = map.entrySet(); for (Iterator<?> localIterator = entrySet.iterator(); localIterator.hasNext();) { Map.Entry<K, V> entry = (Map.Entry) localIterator.next(); for (int i = 0; i < values.length; i++) { Object value = values[i]; if ((entry.getValue() == null) || ((entry.getValue() != null) && (entry.getValue().equals(value)))) { keyList.add(entry.getKey()); } } } return keyList; }
From source file:Main.java
public static String createXml(SortedMap<String, String> sm, String sign) { StringBuilder sb = new StringBuilder(); sb.append("<xml>"); Set<Map.Entry<String, String>> set = sm.entrySet(); for (Iterator<Map.Entry<String, String>> it = set.iterator(); it.hasNext();) { Map.Entry<String, String> entry = it.next(); sb.append("<").append(entry.getKey()).append(">"); sb.append(entry.getValue());/*from ww w.j a v a 2 s .c o m*/ sb.append("</").append(entry.getKey()).append(">"); } sb.append("<sign>").append(sign).append("</sign>"); sb.append("</xml>"); return sb.toString(); }
From source file:Main.java
public static List<String> getAllTables(Uri uri) { List<String> result = new ArrayList<String>(); String mainTable = uri.getLastPathSegment(); result.add(mainTable);//from w w w . j a v a2s.c o m Set<String> queryParameterNames = uri.getQueryParameterNames(); Iterator<String> iterator = queryParameterNames.iterator(); while (iterator.hasNext()) { String table = iterator.next(); if (table.startsWith(TABLE)) { result.add(table.replaceFirst(TABLE, "")); } } return result; }
From source file:Main.java
public static String getStringByMap(Map<String, Object> map) { StringBuffer sb = new StringBuffer(BUFFER_SIZE); Set<String> keys = map.keySet(); Iterator<String> iter = keys.iterator(); while (iter.hasNext()) { String key = iter.next(); Object value = map.get(key); if (value == null) { continue; }//from ww w .ja v a2 s . co m String clsName = value.getClass().getName(); if (value.getClass().isArray()) { sb.append("[").append(key).append(":").append(ARRAY).append(":") .append(toStringByArray((Object[]) value)).append("]"); } else if (STRING.equals(clsName) || INTEGER.equals(clsName) || LONG.equals(clsName) || BOOLEAN.equals(clsName) || DATE.equals(clsName)) { if ("".equals(value.toString())) { continue; } sb.append("[").append(key).append(":").append(value.getClass().getName()).append(":") .append(esc(value.toString())).append("]"); } } return sb.toString(); }