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
How to provide security in java
Can we overload the constructors?
Can you add null to a list java?
What is square root in java?
What is method with example?
What are the files generated after using IDL to java compiler?
What is nextline method in java?
How does class forname work in java?
what is collatration?
Why hashset is used in java?
What is int lol?
What is the purpose of return statement?
What is hashset in java?
How will you add panel to a frame?
What is diamond operator in java?