Skip to main content
Set code fence language to Java, make "Edit" a header
Source Link
 hashMap.keySet().toArray(); // returns an array of keys
 hashMap.values().toArray(); // returns an array of values
hashMap.keySet().toArray(); // returns an array of keys
hashMap.values().toArray(); // returns an array of values

Edit

 

Edit

ShouldIt should be noted that the ordering of both arrays may not be the same, See oxbow_lakes answer for a better approach for iteration when the pair key/values are needed.

 hashMap.keySet().toArray(); // returns an array of keys
 hashMap.values().toArray(); // returns an array of values

Edit

Should be noted that the ordering of both arrays may not be the same, See oxbow_lakes answer for a better approach for iteration when the pair key/values are needed.

hashMap.keySet().toArray(); // returns an array of keys
hashMap.values().toArray(); // returns an array of values
 

Edit

It should be noted that the ordering of both arrays may not be the same, See oxbow_lakes answer for a better approach for iteration when the pair key/values are needed.

 hashMap.keySet().toArray(); // returns an array of keys
 hashMap.values().toArray(); // returns an array of values

Edit

Should be noted that the ordering of both arrays may not be the same, See oxbow_lakes answer for a better approach for iteration when the pair key/values are needed.

 hashMap.keySet().toArray(); // returns an array of keys
 hashMap.values().toArray(); // returns an array of values
 hashMap.keySet().toArray(); // returns an array of keys
 hashMap.values().toArray(); // returns an array of values

Edit

Should be noted that the ordering of both arrays may not be the same, See oxbow_lakes answer for a better approach for iteration when the pair key/values are needed.

Source Link
Landon Kuhn
  • 78.9k
  • 46
  • 111
  • 132

 hashMap.keySet().toArray(); // returns an array of keys
 hashMap.values().toArray(); // returns an array of values