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

Which collection is ordered in java?

0 Answers  


What is string buffer?

0 Answers  


Difference between start() and run() method of thread class?

0 Answers  


What is the difference between jvm and jre? What is an interface?

0 Answers  


what is business objects?

2 Answers  






What is the output of the below java program?

0 Answers  


What is double parsedouble in java?

0 Answers  


Why is flag used in java?

0 Answers  


Does java support multiple inheritance or not?

0 Answers   Hexaware,


what is difference between Action messages and Action errors?

3 Answers   Bio Imagene, TCS,


What is the difference between throw and throws?

10 Answers   IBM,


What is generic type?

0 Answers  


Categories