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 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,184 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?