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

What is the difference between exception and error in java?

0 Answers  


Diff between C++ and java?

9 Answers   TCS,


What will happen to the exception object after exception handling?

0 Answers  


What is the difference between an argument and a parameter?

0 Answers  


Real Time sample code for Encapsulation and Abstraction. where to use abstract and where to use specifies like public private.

2 Answers  






What is the properties class?

0 Answers  


Why are the methods of the Math class are static?

1 Answers  


What is a numeric format?

0 Answers  


Explain the meaning of java applet.

0 Answers   TCS,


What is java command?

0 Answers  


Which programming language is best in future?

0 Answers  


Which java collection does not allow null?

0 Answers  


Categories