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
How do you sort in java?
What are streams?
How do you avoid global variables?
Is it possible to compare various strings with the help of == operator? What are the risks involved?
What are the four pillars of java?
What are the different types of inheritance in java?
How do I know if java is installed?
What are the restrictions that are applied to the java static methods?
How do you clear a list in java?
Explain 5 io best practices?
What is the use of arrays tostring () in java?
Hi all, I am dng a mini project on FileSplitter application which splits the GBs of logfile into Smaller chunks(mbs) depending on the split size." How to handle GBs file? I am getting OutOfMemoryException, when I input such GB sized file. Thx
What are the important features of Java 9 release?
What are the 8 primitive data types in java?
What is string made of?