Hi Friends, can u give code to convert ArrayList to
HashMap and HashMap to ArrayList.



Hi Friends, can u give code to convert ArrayList to HashMap and HashMap to ArrayList...

Answer / 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

More Core Java Interview Questions

Difference between JDK, JRE, JVM

16 Answers   Deloitte, HCL, Mind Tree, Oracle, Reliance, TCS, ThinkBox,


What is the diff. b/w Interfaces & Abstract class?

6 Answers   Ericsson,


I Have a class abstract with one abstract method, so that method should override in the subclass, but i dont want to override, if i am not override what will happen? If compilation will occur then i dont want to give compilation error, then what we need to do??? See the sample program. public abstract class AbstractExample { public abstract void sampleMethod(); } public class AbstractExampleImple extends AbstractExample { }

2 Answers   Mphasis,


Why do we need wrapper classes?

0 Answers  


Which Math method is used to calculate the absolute value of a number?

3 Answers   Accenture,






What is vector capacity in java?

0 Answers  


What are the important features of Java 8 release?

0 Answers  


Is null an object in java?

0 Answers  


Where is stringbuffer stored?

0 Answers  


What is close method? How it's different from Finalize & Dispose?

0 Answers   InfoAxon Technologies,


WHAT IS JDK,JVM,CLASS DEFINE ALL?

2 Answers  


What is the main purpose of serialization in java?

0 Answers  


Categories