| Author |
Max,Min
|
Graham Thorpe
Ranch Hand
Joined: Mar 25, 2002
Posts: 264
|
|
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
|
 |
Timmy Marks
Ranch Hand
Joined: Dec 01, 2003
Posts: 226
|
|
|
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
Joined: Mar 25, 2002
Posts: 264
|
|
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
|
 |
Nigel Browne
Ranch Hand
Joined: May 15, 2001
Posts: 673
|
|
|
Please post the code you have written so far.
|
 |
Nigel Browne
Ranch Hand
Joined: May 15, 2001
Posts: 673
|
|
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
Joined: Dec 01, 2003
Posts: 226
|
|
|
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!
|
 |
 |
|
|
subject: Max,Min
|
|
|