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

Arrays.sort(treets);

Treet[] treets = {treet, secondTreet};

Arrays.sort(treets);

for (Treet exampleTreet : treets){ System.out.println(exampleTreet); }

This method writing it like Treet[] treets = {secondTreet, treet} and then using Array.sort(treets); i cant see any changes. what should happen? in the video craig says about the changes but i do not recognize it in the video as well. And how does Array.sort(treets); works does it sort this two Objects alphabetically or ?

1 Answer

Arrays.sort() works by using the class's compareTo() method to figure out the order to sort the array in. For Strings, compareTo() orders them alphabetically, but other object may have different criteria. You could sort by date, numerically, etc.

If your array of Treets isn't being sorted correctly, I'd look to the compareTo() method you wrote and figure out if there are any issues with it.