Hi Friends, can u give code to convert ArrayList to
HashMap and HashMap to ArrayList.
Answer Posted / 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 View All Answers
Is intellij better than eclipse?
What is a prefix function.write down a code to compute prefix function.
What is character in data type?
Does java set allow duplicates?
how to create daemon thread in java?
What is the difference between I ++ and ++ I in java?
Describe how to implement singleton design pattern in struts.
How does enum work in java?
Write a program to reverse a number in java?
What is the syntax and characteristics of a lambda expression? Explain
Explain java code for recursive solution's base case?
Is java good for beginners?
Is call by reference possible in java?
What is an object's lock and which object's have locks in java programming?
How do you delete a list in java?