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

How to provide security in java

2027


Can we overload the constructors?

762


Can you add null to a list java?

800


What is square root in java?

799


What is method with example?

798


What are the files generated after using IDL to java compiler?

828


What is nextline method in java?

809


How does class forname work in java?

733


what is collatration?

3045


Why hashset is used in java?

764


What is int lol?

878


What is the purpose of return statement?

834


What is hashset in java?

792


How will you add panel to a frame?

873


What is diamond operator in java?

724