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
Write a program to reverse array in place?
What is final variable?
What is use of map in java?
What is string [] java?
What is method reference in java?
What is object of class in java?
What are the legal parameters?
What do you mean by ordered and sorted in collections in java?
How can we create a synchronized collection from given collection?
Write a program to print count of empty strings in java 8?
What is the difference between a break statement and a continue statement?
What is the basic concepts of OOPS?
Explain the scope of a variable.
What is int argc char * argv?
Difference between ‘is-a’ and ‘has-a’ relationship in java?