how copy the hashmap object into arraylist at java program?

Answers were Sorted based on User's Feedback



how copy the hashmap object into arraylist at java program?..

Answer / venkat

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

Is This Answer Correct ?    15 Yes 1 No

how copy the hashmap object into arraylist at java program?..

Answer / abhinaw

HashMap hm = new HashMap();
hm.put("1", "a1");
hm.put("2", "a2");
hm.put("3", "a3");
hm.put("4", "a4");
hm.put("5", "a5");

ArrayList list = new ArrayList();
list.addAll(hm.entrySet());
System.out.println(list);

Is This Answer Correct ?    4 Yes 3 No

how copy the hashmap object into arraylist at java program?..

Answer / fellow java novice

/* HashMap hm; assume hash map has array list objects in it


ArrayList al = (ArrayList) hm.get("name by which arraylist
sits in the hashmap");

/* the crux of the matter is the user of 'get' to access
from hashmap

Is This Answer Correct ?    0 Yes 6 No

how copy the hashmap object into arraylist at java program?..

Answer / deepak

new ArrayList(hashmap.values());

Is This Answer Correct ?    2 Yes 10 No

Post New Answer

More Core Java Interview Questions

What are concepts of OOPS and how are they implemented in Java?

2 Answers   KPIT,


What is externalizable?

0 Answers  


Is java same as core java?

0 Answers  


Explain java coding standards for constants?

0 Answers  


Why is the main method static?

0 Answers  






Which is fastest collection in java?

0 Answers  


Difference difference paint() and paintcomponent()?

0 Answers  


How does static modifier work?

1 Answers   Wipro,


What is the difference between add() and addElement() method in Vector Class ?

2 Answers   TCS,


How do you access command-line arguments within the code?

0 Answers   Flextronics, Hexaware,


What is __ init __ functions?

0 Answers  


What is the maximum size of hashmap in java?

0 Answers  


Categories