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
Lee Reynolds Jr.
5,160 PointsSet comprehension
I've looked at the video and attempted read through the documentation in the Teacher's Notes. For some reason, I can't seem to grasp the concept of Sets. I know what the differences in a TreeSet and a HashSet is. I know how to call a set of monkeys(Set<Monkeys>) for example. What I am not understanding is the recalling correctly what Treets that we are talking about and where in the statement
for (Treet treet : treets)
I'm confused on the different Treets there. Not only there but I just don't get the challenge and what it's asking for. If I am misunderstanding something basic and need to go back and review, I don't mind, I just want to know. It's hard to go to placed like StackOverflow and ask the questions because for some of the questions, I don't know how to ask it the right way. Here it's difficult sometimes because we sometimes don't get a response. Excuse me if I'm rambling but I really want to understand what I'm doing before I continue on further because I feel like I would miss even more if I did. Please please help me someone. Thank you in advance and Happy Coding :)
1 Answer
Daniel Babbev
10,354 PointsSets in java are just like Lists, but their elements are unique, for example you can't have two Strings with the same value in one Set.
The statement:
for (Treet treet : treets){
//do something with each treat
}
is called a for-each-loop, what it basically does is iterating trough all the elements in the given array or Collection. On iteration the value of treet becomes equal to each value of Treet in treets Collection, one at a time.
Lee Reynolds Jr.
5,160 PointsLee Reynolds Jr.
5,160 PointsThank you so much. I am glad you broke it down that simply.