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 |
Which collection is ordered in java?
What is string buffer?
Difference between start() and run() method of thread class?
What is the difference between jvm and jre? What is an interface?
what is business objects?
What is the output of the below java program?
What is double parsedouble in java?
Why is flag used in java?
Does java support multiple inheritance or not?
what is difference between Action messages and Action errors?
What is the difference between throw and throws?
What is generic type?