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 an object's lock and which object's have locks in java programming?
Is java pass by value or pass by reference?
What is arrays aslist in java?
Which collection is thread safe in java?
Why does the integer quotient -0/3 yield 0, but the double quotient -0.0/3.0 yields – 0.0?
What does void * mean?
What is the difference between delete and delete[]
what is the volatile modifier for? : Java thread
Give an example of use of pointers in java class.
What is space character in java?
What was java originally called?
what are three ways in which a thread can enter the waiting state? Or what are different ways in which a thread can enter the waiting state? : Java thread
Why does java not support pointers?
What is the use of hashmap in java?
Can you declare a private method as static?