aspose file tools*
The moose likes Beginning Java and the fly likes Find min from ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Find min from ArrayList" Watch "Find min from ArrayList" New topic
Author

Find min from ArrayList

John Cavados
Greenhorn

Joined: Feb 05, 2013
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

Joined: Jul 14, 2009
Posts: 5
You can do this by writing Collections.sort() with some custom Comparator.

I hope this will work fine.
Michal Plutynski
Greenhorn

Joined: Mar 01, 2012
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
John Cavados
Greenhorn

Joined: Feb 05, 2013
Posts: 3
it's ok. thank you very much
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36486
    
  16
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.
John Cavados
Greenhorn

Joined: Feb 05, 2013
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.

tell me please.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36486
    
  16
It is very simple. You iterate the array/collection, and check whether the value is smaller than your current smallest value.
The hardest part is setting an initial guess, which must not be smaller than the final result. You can try a ridiculously large figure, eg this, or set the initial value of min to the first element in the array/collection.
Finding the maximum is very similar.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Find min from ArrayList
 
Similar Threads
writer's block on assignment, any help?
Home loans in India - fixed or floating ?
sorting
assignment help
buying single store or double store house