Hi Friends, can u give code to convert ArrayList to
HashMap and HashMap to ArrayList.



Hi Friends, can u give code to convert ArrayList to HashMap and HashMap to ArrayList...

Answer / prashant

public class superClass {

public static void main(String[] args) {
ArrayList<String> strArrayList = new
ArrayList<String>();
strArrayList.add("Prashant");
strArrayList.add("Amol");

HashMap<Integer, String> hashMap = new
HashMap<Integer, String>();
for(int i = 0;i<strArrayList.size();i++){
hashMap.put(i, strArrayList.get(i));
}
System.out.println(hashMap);
}

}

Is This Answer Correct ?    20 Yes 4 No

Post New Answer

More Core Java Interview Questions

How many bits are in a sentence?

0 Answers  


Why doesn't the java library use a randomized version of quicksort?

0 Answers  


What is a marker interface?

1 Answers  


What is meant by Encapsulation? Can you write a class to explain encapsulation?

8 Answers   Ness Technologies,


What defines function?

0 Answers  


How will you reverse a singly-link list?

0 Answers   Akamai Technologies,


Can u write constructor in abstract.If yes den when it will be invoked.

4 Answers   SunGard,


Which class represents the socket that both the client and server use to communicate with each other?

0 Answers  


What happens when heap memory is full?

0 Answers  


What is the difference between a synchronized method and a synchronized block?

0 Answers  


What is meant by object?

0 Answers  


What is string :: npos?

0 Answers  


Categories