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


Please Help Members By Posting Answers For Below Questions

What is the concept of multithreading?

729


What is the use of runnable interface?

836


What is int lol?

862


Why java is used everywhere?

755


What is integer size in java?

706


Explain jdk, jre and jvm?

765


What is the biggest integer?

803


What is string intern in java?

766


Why collection doesn’t extend cloneable and serializable interfaces?

872


Write a code to create a trigger to call a stored procedure

738


What is proper subset?

758


what is comparable and comparator interface?

764


Is a class an object?

778


what is server side caching?

1807


What are the basic control structures?

718