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 ArrayLists

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.