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 length in java?
What are static initalizers in java ?
When throws keyword is used?
What is variable and rules of variable?
What is difference between calling start() and run() method of thread?
What are the types of exceptions?
Can java object be locked down for exclusive use by a given thread?
What are advantages and disadvantages of OOPs?
What are aggregate functions explain with examples?
What are the benefits of immutable objects?
What is the largest long allowed by java?
Differentiate between vector and array list.
What is methodological theory?
How do you declare a destructor in java?
Why synchronization is important in java?