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 the difference between equals() and?
What are the topics in advance java?
What is the concatenation operator in java?
What’s the difference between applets and standalone program?
What is the purpose of assert keyword used in jdk1.4.x?
What do you mean by stream pipelining in java 8?
What is a for loop in java?
What is the purpose of stub and skeleton?
Explain listiterator and methods in listiterator?
difference between byte stream class and character stream class?
What is difference between add() and addelement() in vector?
What is procedure writing?
Explain about class in java?
What is a numeric literal?
Which containers use a flowlayout as their default layout in java programming?