Help with Finding Max and Min Values of ArrayList

Hey guys, how do you find the max value and min value of an ArrayList without using collections? I know this is the way you find the max and min value of an array but I don't get how you would do it for an ArrayList.

Code Java:

//highest value
int[] numbers = new int[50];
int highest = numbers[0];
for (int i = 1; i < numbers.length; i++)
{
if (numbers[i] > highest)
highest = numbers[i];
}
//lowest value
int lowest = numbers[0];
for (int i = 1; i < numbers.length; i++)
{
if (numbers[i] < lowest)
lowest = numbers[i];
}

Re: Help with Finding Max and Min Values of ArrayList

You would do it the same way with a slight change in syntax...iterate over the List as you would an array but using the List/ArrayList functions like get and size (see List (Java Platform SE 6) for available functions you can use)

Re: Help with Finding Max and Min Values of ArrayList

Thanks for pointing me to the ArrayList functions.

Re: Help with Finding Max and Min Values of ArrayList

A more efficient method is to check if new item is MAX or MIN before adding it to the List. That way there is no need to iterate over the entire list to find them.