Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!

# Find min from ArrayList

Greenhorn
Posts: 3
Land: ID: L1234, Price: 50000€, Description: Artemida Attikis, isForSale? true, Squaremeter 120m2
Flat: ID: FF4234, Price: 120000€, Description: Abelokipoi Athens, isForSale? true, Squaremeter 72m2, Rooms: 2, Floors: 1
House: ID: HC178, Price: 250000€, Description: for sale, isForSale? true, Squaremeter 120m2, Bedrooms: 4
Flat: ID: FL2, Price: 105000€, Description: Patisia Athens, isForSale? false, Squaremeter 70m2, Rooms: 2, Floors: 2
House: ID: H12311, Price: 310000€, Description: for sale, isForSale? true, Squaremeter 180m2, Bedrooms: 5
House: ID: H12621, Price: 280000€, Description: sold, isForSale? false, Squaremeter 200m2, Bedrooms: 5
House: ID: H72621, Price: 210000€, Description: sold, isForSale? false, Squaremeter 110m2, Bedrooms: 3
Land: ID: L1288, Price: 50000€, Description: Artemida Attikis, isForSale? false, Squaremeter 130m2
Land: ID: L1298, Price: 45000€, Description: Artemida Attikis, isForSale? false, Squaremeter 130m2

here is my arraylist.
how can i calculate the cheapest one? (price)

Rakib Jahin
Greenhorn
Posts: 5
• 1
You can do this by writing Collections.sort() with some custom Comparator.

I hope this will work fine.

Michal Plutynski
Greenhorn
Posts: 14
Hi,
please tell us if this answer is ok for you, or you want to calculate smallest price for 1 square meter? and then sort collection

Greenhorn
Posts: 3
it's ok. thank you very much

Campbell Ritchie
Sheriff
Posts: 48921
58
Rakib Jahin wrote:You can do this by writing Collections.sort() with some custom Comparator.
. . .
I hope this will work fine.
I do not think that is a good answer to the question, I am afraid. There is a much simpler way to find a minimum or maximum.

Greenhorn
Posts: 3
Campbell Ritchie wrote:
Rakib Jahin wrote:You can do this by writing Collections.sort() with some custom Comparator.
. . .
I hope this will work fine.
I do not think that is a good answer to the question, I am afraid. There is a much simpler way to find a minimum or maximum.