Ive got a collection that is populated by some key/value pairs.
How can i iterate ie to get its each key/value pair?
How can i iterate ie to get its each key/value pair?
public void testKeySet(HashMap hashMap) { Set keySet = hashMap.keySet(); Iterator keySetIterator = keySet.iterator(); while(keySetIterator.hasNext()) { Object key = keySetIterator.next(); Object value = hashMap.get(key); System.out.println("key="+key+",value="+value); } }
public void testKeySet(HashMap hashMap) { Set keySet = hashMap.keySet(); Iterator keySetIterator = keySet.iterator(); while(keySetIterator.hasNext()) { Object key = keySetIterator.next(); Object value = hashMap.get(key); System.out.println("key="+key+",value="+value); } }
ArrayList<E> "voucherTransactionCols"= ArrayList<E> (id=122) E[] elementData= Object[10] (id=133) Object [0]= HashMap<K,V> (id=135) Object [1]= HashMap<K,V> (id=137) Set<Entry<K,V>> entrySet= HashMap$EntrySet (id=150) Set<K> keySet= null float loadFactor= 0.75 int modCount= 2 int size= 2 HashMap$Entry<K,V>[] table= HashMap$Entry<K,V>[16] (id=151) HashMap$Entry<K,V> [0]= null HashMap$Entry<K,V> [1]= null HashMap$Entry<K,V> [2]= null HashMap$Entry<K,V> [3]= null HashMap$Entry<K,V> [4]= null HashMap$Entry<K,V> [5]= null HashMap$Entry<K,V> [6]= HashMap$Entry<K,V> (id=152) int hash= 361649174 K key= "liability" HashMap$Entry<K,V> next= null V value= "A" HashMap$Entry<K,V> [7]= null HashMap$Entry<K,V> [8]= HashMap$Entry<K,V> (id=153) int hash= -1446859816 K key= "lamount" HashMap$Entry<K,V> next= null V value= "" HashMap$Entry<K,V> [9]= null HashMap$Entry<K,V> [10]= null HashMap$Entry<K,V> [11]= null HashMap$Entry<K,V> [12]= null HashMap$Entry<K,V> [13]= null HashMap$Entry<K,V> [14]= null HashMap$Entry<K,V> [15]= null int threshold= 12 Collection<V> values= null Object [2]= HashMap<K,V> (id=138) Object [3]= HashMap<K,V> (id=139) Object [4]= HashMap<K,V> (id=140) Object [5]= null Object [6]= null Object [7]= null Object [8]= null Object [9]= null int modCount= 5 int size= 5
for (Iterator iter = voucherTransactionCols.iterator(); iter.hasNext();) { Object object = (Object) iter.next(); HashMap campusModel = (HashMap) object; Set keySet = campusModel.keySet(); Iterator keySetIterator = keySet.iterator(); Object key = keySetIterator.next();
Comment