Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Data Structures - Retired 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#@']+");

}

}