As HashMap contains key-value pairs, there are three ways you can convert given HashMap to ArrayList. You can convert HashMap keys into ArrayList or you can convert HashMap values into ArrayList or you can convert key-value pairs into ArrayList.
examples:
>(entrySet);
examples:
a) Conversion Of HashMap Keys Into ArrayList :
HashMap<String, String> map = new HashMap<String,
String>();
Set<String> keySet = map.keySet();
ArrayList<String> listOfKeys = new
ArrayList<String>(keySet);
b) Conversion Of HashMap Values Into ArrayList :
HashMap<String, String> map = new HashMap<String,
String>();
Collection<String> values = map.values();
ArrayList<String> listOfValues = new
ArrayList<String>(values);
c) Conversion Of HashMap’s Key-Value Pairs Into
ArrayList :
HashMap<String, String> map = new HashMap<String,
String>();
Set<Entry<String, String>> entrySet =
map.entrySet();
ArrayList<Entry<String, String>> listOfEntry =
new ArrayList<Entry<String,String>
No comments:
Post a Comment