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

Kshatriiya .
Kshatriiya .
1,464 Points

Wouldn't Treet originalTreets = treets[0] just give you one element at index position 0?

Hello, I'm confused as to how originalTreets can accommodate the following code: for (String hashtag: originalTreet.getHashTags()) { System.out.println(hashtag);

originalTreets only stores one element that is in treets[0] index at 0?

1 Answer

Florian Tönjes
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Florian Tönjes
Full Stack JavaScript Techdegree Graduate 50,856 Points

Hey Kshatriiya ,

yes there is only one element stored at treets[0]. Also, in the video the variable is called "originalTreet", without the "s" that you wrote in your question.

Then on this one treet the getHashTags() method is called which returns a list of strings, which are the hashtags. The for-each loop then iterates over each one of them and prints it out.