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 meant by memory leak?

542


What is string builder?

470


What is the difference between notify and notifyall method?

616


What are the two environment variables that must be set in order to run any java programs?

531


What string is utf8?

547






Difference between method overloading and overriding.

581


What is parse method?

542


What are meta-annotations?

553


What type of variable is error flag?

587


What is string pooling concept?

555


What is lazy programming?

567


What is the collections api?

573


Define nashorn in java8.

570


Can a class be private or protected in java?

558


Is a boolean 1 bit?

614