Java Java Data Structures Exploring the Java Collection Framework Sets

Shariq Shaikh
Shariq Shaikh
13,945 Points

The Hash Tags and Mentions are not loading once I execute the program from the console.

I did everything Craig did in the video, double checked to see if the were any error and all that's displaying once I run the program from the console is:

There are 58 treets. Hash tags: [] Mentions: []

The data that was in the video isn't loading when I run the program. Any thoughts?

3 Answers

We won't be able to do you any good without you posting your code for us. When you do, please format it in the right way. In case you don't know how click here

Shariq Shaikh
Shariq Shaikh
13,945 Points
import java.util.Arrays;
import java.util.Date;
import java.util.Set;
import java.util.HashSet;
import java.util.Map;
import java.util.HashMap;

import com.teamtreehouse.Treet;
import com.teamtreehouse.Treets;



public class Example {

  public static void main(String[] args) {
    Treet[] treets = Treets.load();
    System.out.printf("There are %d treets. %n",
                     treets.length);
    Set<String> allHashTags = new HashSet<String>();
    Set<String> allMentions = new HashSet<String>();
    for (Treet treet : treets) {
      allHashTags.addAll(treet.getHashTags());
      allMentions.addAll(treet.getMentions()); 
    }
    System.out.printf("Hash tags: %s %n", allHashTags);
    System.out.printf("Mentions: %s %n", allMentions);
    Map<String, Integer> hashTagCounts = new HashMap<String, Integer>();
    for (Treet treet : treets) {
      for (String hashTag : treet.getHashTags()) {
        Integer count = hashTagCounts.get(hashTag);
        if (count == null) {
          count = 0;
        }
        count++;
        hashTagCounts.put(hashTag, count);

      }
    }
    System.out.printf("Hash tag counts: %s %n", hashTagCounts);
 }
}

Hey, I have the same problem, and the same code. What should I change to see those tags and mentions?

Colby Wise
Colby Wise
3,165 Points

I believe this is the issue. Craig mentioned this in another post:

Craig Dennis about 1 year ago Hi Manish!

Yeah you are right I load it by deserializing, there is a class called Treets that does the deserialization of an array of Treet objects. I used the Twitter API to get them originally, and made the Treet object array and then serialized it. Unfortunately after a period of time the Treets fall off, so those are locked in time to when I did the video.

Hope that helps!