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
In Java list the methods that can be overridden?
How big is a boolean?
What do the thread?class methods run() and start() do?
What are generic methods?
How to create com object in Java?
Can singleton class be serialized?
Explain the overview of UDP messaging.
Why do we need data serialization?
What is the purpose of main function in java?
what is collatration?
What is * argv?
Explain the reason behind ending a program with a system.exit(0)?
What is the difference between a switch statement and an if statement?
Which arithmetic operations can result in the throwing of an arithmeticexception?
Explain the Propertie sof class?