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
What is protected access modifier?
How many tetrahedral voids are there in bcc?
Write a program based on Java script program.
Where are variables stored?
What is sizeof in java?
What is the SimpleTimeZone class?
Is java pass by value or pass by reference?
What do you mean by boolean?
What is stringreader?
Explain spliterator in java8?
Can a class extend more than one class?
What is a class in java?
Is array primitive data type in java?
Why is logger singleton?
Why string is not thread safe?