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 ArrayLists

Diego Marrs
Diego Marrs
8,243 Points

Question about challenge.

I have a few questions about this challenge:

private List<String> getExternalLinks() {
    List<String> result = new ArrayList<String>();
    for (String word : getWords()) {
      if (word.startsWith("http")) {
        result.add(word);
      }
    }
    return result;
  }
  1. Why should the method be public?
  2. How come we don't use getBody()?

Also, i'm still a little confused on lists vs. arrays.

Help is appreciated!

1 Answer

Diego,

1) if it is private then it would not be available from other classes. See https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html for more detail.

2) getBody() returns the text, but to find http it's easier to first split the body text into separate words, which is what getWords() does.

3) List is an interface, ArrayList is a class that implements that interface. You cannot create List objects. You can create ArrayList objects.