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 digits is int32?

0 Answers  


What is member in java?

0 Answers  


What are the application of stack?

0 Answers  


Are arrays passed by reference in java?

0 Answers  


What does this mean java?

0 Answers  






What is busy spin, and why should you use it?

0 Answers  


Create a form of user Login in JSP, that accepts the user name and password from user and authenticate it with user names and passwords stored in database. (Plz provide me answer immediately)

1 Answers   ABC,


What is object-oriented paradigm?

0 Answers  


What is nextint java?

0 Answers  


What is an argument java?

0 Answers  


These static constructors are correct ? class A { statc intA() { } static A(int x,int y) { } static A(int x) { } }

0 Answers   HCL,


Can constructor be protected in java?

0 Answers  


Categories