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 length in java?

566


What are static initalizers in java ?

577


When throws keyword is used?

578


What is variable and rules of variable?

512


What is difference between calling start() and run() method of thread?

555






What are the types of exceptions?

589


Can java object be locked down for exclusive use by a given thread?

582


What are advantages and disadvantages of OOPs?

625


What are aggregate functions explain with examples?

522


What are the benefits of immutable objects?

532


What is the largest long allowed by java?

532


Differentiate between vector and array list.

634


What is methodological theory?

524


How do you declare a destructor in java?

502


Why synchronization is important in java?

558