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 Using ArrayLists

leo 001
leo 001
2,357 Points

what is the object that is calling getWords()

private List<String> getWordsPrefixedWith(String prefix){
    List<String> results = new ArrayList<String>();
    for ( String word: getWords()){
      if(word.startsWith(prefix)){
        results.add(word);
      }
    }
    return results;
  }

what is the object that is calling getWords()? when do we need object to call and when need not?

1 Answer

Rob Bridges
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

Hey there Leo,

There really isn't a method calling getWords() since Java is strong object oriented almost everything is a method, however to clarify remember when we made the method getWords() to go through the body of our treet, what it did was first go through each word in the description, and return it using regular Expression to break it on the spaces. We then returned the String array initially created as an ArrayList, so that's where getWords() comes from. it's an ArrayList list of each word.

With that being said;

We are using that method to go through each word that that method returns, and if it begins with prefix that we passed into the method, it will first add it to our list of Strings called results. and then return that same list once it has gone through every word and checked to see it begun with our prefix.

You'll later use this method to search for any words in the treets that we received that start with @, or #.

Thanks, hope this helps.