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 trialArtur Argasinski
1,318 PointsWhy isn't treetsByAuthor.put(treet.getAuthor(), authoredTreets); at the end of the second for loop in Example.java?
if the second for loop follows the same logic as the first in Example.java we want to check whether an author already submitted one treet. If this is not the case we go into the if statement were we initialize authoredTreets as ArrayList and put it next to the corresponding author.
But if the author already has submitted a tweet we add it to our list authoredTreets.
Now comes the part I dont get. Because in my opinion now the list authoredTreets has two entries and following the same logic we should assign those two entries to the corresponding key in treetsByAuthor with:
treetsByAuthor.put(treet.getAuthor(), authoredTreets);
So that we account for the case that one author submitted multiple treets.
I would be very thankful if someone could clarify this for me :)
greetings, Artur
1 Answer
sldknflskdngd
9,985 PointsI was thinking about the same thing. BUT here is the reason why I think it works. Since HashMap value is point to specific list, we can just add the new Treet into the list. So by adding a new treet to the list AND since we are not changing the pointer to that specific list, whenever we call the hashmap my the key we can get the pointer to the list that contains all the treets.
Bayar Bogdanov
2,350 PointsBayar Bogdanov
2,350 PointsHello Artur, I think you're right, but somehow this strange code in if statement just worked.