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
Can private class be inherited in java?
Difference between static binding and dynamic binding?
Differences between external iteration and internal iteration?
How many arguments can be passed to main ()?
What is the same as procedures?
What does int argc char * argv [] mean?
Does java trim remove newline?
Explain about the main() method in java?
List down the methods and interfaces of collection class in java.
What is difference between static class and normal class?
How do you compare two objects?
What is purpose of keyword void?
How thread scheduler schedule the task?
What is an inner class in java?
What is used of static keyword in java?