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 Organizing Data Comparable

I guessed this answer correct but i don't know why.

The question was to make a list of BlogPosts sorting on oldest first. But if i wanted to do the newest first? than i really have no clue on what to change in the code.

1 Answer

Ezekiel dela Peña
Ezekiel dela Peña
6,231 Points

you just have to return the value of what you are comparing to get the correct answer.

return mCreationDate.compareTo(obj.getCreationDate());

or you can also do this approach

int dateCmp = mCreationDate.compareTo(obj.getCreationDate());

// This is for double checking purposes.
if(dateCmp == 0) {
    return mTitle.compareTo(obj.getTitle());
} else {
    return dateCmp;
}