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
What is the purpose of final keyword and when to use it?
Differentiate between the constructors and methods in java?
how can i use a nonsynchronized hashtable?
How many ways can we create singleton class?
What are recursive functions?
What is the difference between superclass and subclass?
What is the use of isempty in java?
What do you mean by inner class in java?
What is difference between fileinputstream and filereader in java?
Can we use String with switch case?
What is preflight request?
What does main method?
What are the four integer types supported by java?
Which package has light weight components?
What is meant by JVM? Is JVM platform independent or not?