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

Kevin Faust
Kevin Faust
15,353 Points

serialization made this code all messed up

Treet originalTreet = treets[0];
    System.out.println("Hastags:");
    for (String hastag : originalTreet.getHashTags()) {
     System.out.println(hastag); 
    }

i dont understand this. we did Treet[] treets = Treets.load(); which does some deserialization stuff. and then we create a new treet object equal to treets[0]. why [0]..is there anything more in that array? and then i get how we loop through the originaltreet object but why are we looping. i thought originaltreet only has one thing inside it? help pls

1 Answer

Treet[] treets = Treets.load() creates a list of Treet objects. treets[0] is going to be a Treet object, you're just creating a new variable to reference that Treet. When you loop you're looping through all the tags in getHashTags(), which is an array of String objects.

Kevin Faust
Kevin Faust
15,353 Points

hey cory,

what if we did treets[1]?

Kevin Faust
Kevin Faust
15,353 Points

ohh nvm i understand now. [0] was just as an example. we couldve went up to [57]