• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Find min from ArrayList  RSS feed

 
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)
 
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.
 
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
 
Marshal
Posts: 64483
225
  • 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
Marshal
Posts: 64483
225
  • 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
Boost this thread!