Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Find min from ArrayList

 
John Cavados
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do this by writing Collections.sort() with some custom Comparator.

I hope this will work fine.
 
Michal Plutynski
Greenhorn
Posts: 14
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's ok. thank you very much
 
Campbell Ritchie
Sheriff
Pie
Posts: 50232
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50232
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic