> It says thet arrays are the members of java
> collections framework but
The class Arrays is something very different from an array.
> i cannot apply Collections.max() method to array...
That's because Collections.max takes a collection as argument, and an array is not a collection.
Kaj
If it is indeed an array, I would suggest writing
a simple loop that go through every element exactly once
(and along the way, you have a variable "max"
that records the maximum entry)
To use Collections.max() you would have to convert
the existing array into a Collection object, and then walk over
it... that introduces overhead.
> but anyway,could you suggest please easiest way to
> find max value in array?
If want to avoid writing your own algorithm and want a quick shortcut, try java.util.Arrays.sort() function and pick the last (or first) element in the resulting array.
Note: If you have object elements in the array, ensure that you either implement Comaprable interface on those elements or provide a Comparator implementation to the Array api.
-BJ
edited by: Bimalesh
> If want to avoid writing your own algorithm and want
> a quick shortcut, try java.util.Arrays.sort()
> function and pick the last (or first) element in the
> resulting array.
I'd hardly call it an algorithm. It's just one for statement to loop through the array once to find the max value. This approach will find it in O(n), where the sort approach will take an average of O(n*log(n)).
So I'd say the quickest way will be to loop through the array just once.