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 downcasting?
What is a default constructor and also define copy contrucyor?
In a program, initializing an array of 100 KB is throwing an out of memory exception while there is 100 MB of memory available. Why?
what is synchronization? : Java thread
What happens when I use / and % with a negative numerator?
What is a lambda expression ? What's its use ?
Is arraylist zero based?
How can you avoid serialization in child class if the base class is implementing the serializable interface?
What is included in core java?
Outline the major features of java.
What is a private class in java?
What is java util?
Is zero a positive integer?
we have syntax like for(int var : arrayName) this syntax is to find whether a number is in the array or not.but i want to know how to find that number's location.
What is the advantage of OOP in java?