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 does pointer mean?
What is boolean example?
How do you add an arraylist to an array in java?
Can a lock be acquired on a class in java programming?
Is it necessary for the port addresses to be unique? Explain with reason.
whar are the draw backs of programming lang step by step in Clang and next in C++ and next and in Java nad in .Net
What is xslt in java?
How do you do descending order in java?
What is contract between hashcode and equal method?
What is thread safe singleton?
What is the format specifier?
Is a copy constructor?
What is r in java?
What is array initialization in java?
Is set ordered in java?