fork download
  1. import java.util.HashMap;
  2. import java.util.Map;
  3. import java.util.stream.Collectors;
  4.  
  5. class Ideone {
  6. public static void main(String[] args) {
  7. Map<String, Integer> myMap = new HashMap<>();
  8. myMap.put("Some", 2);
  9. myMap.put("Example", 4);
  10. myMap.put("Word", 6);
  11.  
  12. System.out.println(countWords(myMap));
  13. }
  14.  
  15. public static String countWords(Map<String, Integer> stringIntegerHashMap) {
  16. return stringIntegerHashMap.entrySet().stream()
  17. .map(entry -> entry.getKey() + " - " + entry.getValue())
  18. .collect(Collectors.joining("\r\n"));
  19. }
  20. }
Success #stdin #stdout 0.12s 50732KB
stdin
Standard input is empty
stdout
Some - 2
Word - 6
Example - 4