Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Data Structures Exploring the Java Collection Framework Maps

Steven Morimoto
PLUS
Steven Morimoto
Courses Plus Student 1,836 Points

Java Maps moduel

Hi,

I've been through the video and typed out the code in Workspaces. When I attempt to compile Example it keeps on giving me an errors. One of the errors is about not being able to find getHashTags() in treet. Is there a line of code that I am missing within the Treet class, or is there something else that I'm missing?

I appreciate all of the help,

Steve

2 Answers

Hey Steve,

Can you paste the code that you are trying so I can take a look?

Thanks!

Steven Morimoto
PLUS
Steven Morimoto
Courses Plus Student 1,836 Points

Sure:

Example.java

import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.HashSet; //Sets import java.util.Map; import java.util.Set; //Sets

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>(); //Sets Set<String> allMentions = new HashSet<String>(); //Sets for(Treet treet : treets) //Sets { allHashTags.addAll(treet.getHashTags()); //Sets } System.out.printf("Hash tags: %s %n", allHashTags); System.out.printf("Mentions: %s %n", allMentions);

Map<String, Integer> hashTagsCounts = new HashMap<String, Integer>();   //Maps
for(Treet treet : treets){    //see line 15
  for(String hashTag : treet.getHashTags())   //for each treet loop through each hash tag in
                                              //that treet
  {
    Integer count = hashTagCounts.get(hashTags);
    if(count == null)
    {
      count = 0;
    }
    count++;
    hashTagCount.put(hashTag, count);
  }
}
System.out.printf("Hash tag counts %s %n", hashTagCounts);

}

}

Treet.java

package com.teamtreehouse;

import java.io.Serializable; import java.util.Date;

public class Treet implements Comparable, Serializable { private static final long serialVersionUID = 7146681148113043748L; private String mAuthor; private String mDescription; private Date mCreationDate;

public Treet(String author, String description, Date creationDate) { mAuthor = author; mDescription = description; mCreationDate = creationDate; }

@Override public String toString() { return String.format("Treet: \"%s\" by %s on %s", mDescription, mAuthor, mCreationDate); }

@Override public int compareTo(Object obj) { Treet other = (Treet) obj; if (equals(other)) { return 0; } int dateCmp = mCreationDate.compareTo(other.mCreationDate); if (dateCmp == 0) { return mDescription.compareTo(other.mDescription); } return dateCmp; }

public String getAuthor() { return mAuthor; }

public String getDescription() { return mDescription; }

public Date getCreationDate() { return mCreationDate; }

public String[] getWords() { return mDescription.toLowerCase().split("[^\w#@']+");

}

}