I have an ArrayList<HashMap<String, String>>. I'd like to quickly extract from this a new ArrayList<String> comprising all the keys.
How do I do this?
I have an ArrayList<HashMap<String, String>>. I'd like to quickly extract from this a new ArrayList<String> comprising all the keys.
How do I do this?
I suggest you do
If you're not interested in duplicate keys (i.e., if you don't want two identical entries in
allKeysjust because it exists as key in two maps) I would suggest you letallKeysbe of typeHashSet<String>instead.After traversal you could do
allKeysList = new ArrayList<String>(allKeys);if order is important to you in the end.