Advertisement
Guest User

Solution for Maps Challenge

a guest
Sep 14th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.40 KB | None | 0 0
  1. public Map<String,Integer> getCategoryCounts () {
  2.   Map<String,Integer> categoryCounts = new HashMap<String,Integer>();
  3.     for (BlogPost post: mPosts) {
  4.       String category = post.getCategory();
  5.       Integer count = categoryCounts.get(category);
  6.       if(count == null){
  7.         count = 0;
  8.       }
  9.       count++;
  10.       categoryCounts.put(category, count);
  11.     }
  12.      return categoryCounts;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement