• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Max,Min

 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Can any body tell me how i can find out max and min value using the following format

{ArrCol1=1, ArrCol2=2}
{ArrCol1=2, ArrCol2=4}
{ArrCol1=3, ArrCol2=6}
{ArrCol1=4, ArrCol2=8}
{ArrCol1=5, ArrCol2=10}

The above values are Hashmap

So i want to find out ArrCol1 as Min/Max values and ArrCol2 as Min/Max Values

Like

Min of ArrCol1=1
Max of ArrCol1=5

Min of ArrCol2=2
Max of ArrCol2=10


Thanks
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this some kind of homework assignment? The answer to the question could depend on it. Assuming it is, describe finding the minimum algorithmically. Maybe that will help you see a solution.
 
Graham Thorpe
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
its not assignment i want to find out min and max for this Col1 ,Col2 individually hashmap result {{Col1=41, Col2=45},{Col1=56, Col2=12},{Col1=10, Col2=11}}

Using Collections.min(collection)
Collections.max(collection)

Minimum of Col1=10
Maximum of Col1=56

and same time Minimum of Col2=11
Maximum of Col2=45
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post the code you have written so far.
 
Nigel Browne
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read the documentation for the map interface, if you had you would realise that.
1 HashMap is an implementation of Map i.e an object that maps keys to values
2 A map cannot contain duplicate keys
3 each key can map to at most one value.
 
Timmy Marks
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you seem to already know it. You just need to realize that Set implements Collection, and that there are HashMap methods for getting the set of keys and the collection of values. Just make sure that your keys and values are Comparable or that you have a Comparator!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic