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 Sets

A little help needed

I'm working on this and I feel like I've implemented the solution correctly. No compile errors, but the automated check doesn't seem to be seeing my method. The error I'm getting is "Did you add a method getAllAuthors() to the blog class?

com/example/Blog.java
package com.example;

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

public class Blog {
  List<BlogPost> mPosts;

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

  public List<BlogPost> getPosts() {
    return mPosts;
  }
  public Set<String> getAllAuthors(List<BlogPost> blogPosts)
  {
    Set<String> authorList = new TreeSet();
    for (BlogPost blogPost : blogPosts)
    {
      authorList.add(blogPost.getAuthor());
    }
    return authorList;
  }
}

1 Answer

Jason Wiram
Jason Wiram
42,762 Points

You are very close. You don't need to pass any parameters to the getAllAuthors() method. The Blog class constructor takes 'List<BlogPost> blogPosts' as a parameter and initializes it to the field mPosts. That is the list you will iterate over in your function. Make sense?