Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2015
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Date;
  3. import java.util.HashSet;
  4. import java.util.Set;
  5. import java.util.TreeSet;
  6. import java.util.Map;
  7. import java.util.HashMap;
  8.  
  9. import com.teamtreehouse.Treet;
  10. import com.teamtreehouse.Treets;
  11.  
  12.  
  13. public class Example {
  14.  
  15.   public static void main(String[] args) {
  16.     Treet[] treets = Treets.load();
  17.     System.out.printf("There are %d treets. %n",
  18.                      treets.length);
  19.     Set<String> allHashTags = new HashSet<String>();
  20.     Set<String> allMentions = new TreeSet<String>();
  21.     for (Treet treet : treets) {
  22.       allHashTags.addAll(treet.getHashTags());
  23.       allMentions.addAll(treet.getMentions());
  24.     }
  25.     System.out.printf("Hash tags: %s %n", allHashTags);
  26.     System.out.printf("Mentions: %s %n", allMentions);
  27.   }
  28.  
  29.   Map<String, Integer> hashTagCounts = new HashMap<String, Integer>();
  30.   for (Treet treet : treets) {
  31.     for (String hashTag : treet.getHashTags()) {
  32.       Integer count = hashTagCounts.get(hashTag);
  33.       if (count == null) {
  34.         count = 0;
  35.       }
  36.       count++;
  37.       hashTagCounts.put(hashTag, count);
  38.     }
  39.   }
  40.   System.out.printf("Hash tag counts: %s %n", hashTagCounts);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement