Thursday, January 31, 2019

HashMap CollectionValues example

package com.concretepage;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
public class HashMapCollectionValues {
public static void main(String[] args) {
HashMap<String, String> hmap = new HashMap<>();
hmap.put("One", "One");
hmap.put("Two", "Two");
Collection<String> ref = hmap.values();
ArrayList<String> arrayListAgain = new ArrayList<>(ref);
Iterator<String> refAgain = arrayListAgain.iterator();
while(refAgain.hasNext()) {
System.out.println(refAgain.next());
}
}
}

No comments:

Post a Comment