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
Riley Bolen
26,711 PointsSorting the items in an ArrayList of Objects
Here is my problem: I have a Property class that will eventually let users input data and create Property objects. The constructor looks like this : new Property( int beds, int baths, int squarefeet, int price, double rent, String zipCode); I have set it up so that when a user makes a new property it will be added to an ArrayList of Property objects. The Property class has a method called getCFScore(); that returns a double. How can I sort the Properties in this list by the value returned by getCFScore? (Property with the highest value is 1st, second highest is 2nd and so on). Thanks in advance.
Riley Bolen
26,711 PointsRiley Bolen
26,711 PointsUPDATE: I figured it out! this is what i did:
I did a println of the getCFScore values for the Property at index 0, 1, 2 for the list before and after sorting and here are the results:
0.51 , 0.36 , 0.42 ---> 0.36 , 0.42 , 0.51