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 Exploring the Java Collection Framework Sets

Don't know what to do.

2 Answers

Allan Clark
Allan Clark
10,810 Points
Set<String> links = new TreeSet<String>();
for (String word : links) {

This creates a new empty TreeSet and then starts a for each loop on that set. Because it is an empty Set the for each is skipped and the Set is returned. What you want to do here is create that Set to collect all the authors in the BlogPosts. Then go through each BlogPost and add the author to the Set.

Set<String> authors = new TreeSet<String>();
for(BlogPost post : mPosts) {
     authors.add(post.getAuthor());
}

And of course return your authors Set.

Allan Clark
Allan Clark
10,810 Points

Saw what you posted on the other forum, gonna respond on here for moar points MUAHAHAHA :D Also not to confuse conversations.

Try adding the generic version of set to the variable declaration.

Set allAuthors = new TreeSet<String>(); 

change that Set to Set<String>

Here's my Blog class:

package com.example;

import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.ArrayList;

public class Blog {
  List<BlogPost> mPosts;

  public Blog(List<BlogPost> posts) {
    mPosts = posts;
  }

  public List<BlogPost> getPosts() {
    return mPosts;
  }
    public Set<String> getAllAuthors() {
    Set<String> links = new TreeSet<String>();
    for (String word : links) {
      if (word.startsWith("@")) {
        links.add(word);
      }
    }
    return links;
  }
}

It says:

:heavy_multiplication_x: Bummer! Expected 5 authors, but received 0