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 meant by memory leak?
What is string builder?
What is the difference between notify and notifyall method?
What are the two environment variables that must be set in order to run any java programs?
What string is utf8?
Difference between method overloading and overriding.
What is parse method?
What are meta-annotations?
What type of variable is error flag?
What is string pooling concept?
What is lazy programming?
What is the collections api?
Define nashorn in java8.
Can a class be private or protected in java?
Is a boolean 1 bit?