Answer Posted / srikanth m
List<String> list = new ArrayList<String>();
list.add("abc");
list.add("def");
list.add("abc");
HashMap<String, Integer> map = new HashMap<String, Integer>();
for (String str : list) {
Integer c = (Integer) map.get(str);
if (c == null || c == 0) {
map.put(str, 1);
} else {
map.put(str, ++c);
}
}
System.out.println(map);
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Which is better arraylist or vector?
What is the difference between instanceof and isinstance?
What is the difference between the boolean & operator and the && operator in java programming?
Write a program to print fibonacci series up to count 10.
why Interface used?
Can we use different return types for methods when overridden?
What interface is extended by awt event listeners?
Explain the difference between throw and throws in java?
Where import statement is used in a java program?
What is java beans?
What is a parameter used for?
How can we access some class in another class in java?
List the interfaces which extends collection interface?
What is a vector in java?
What is the program compilation process?