Archaimot Archaimot - 1 year ago 51
Java Question

Returning values from an ArrayList

I had this code working for an Array...then re-read the instructions to find it specifically calls for an array LIST. I cannot seem to convert the methods beneath to be acceptable for the ArrayList...Please assist in how I need to change the verbiage...See below for a sample method:

public static int returnMin(ArrayList intArr)
{ //Return the Min Value.
int minValue = intArr.get(0);
for(int i=1;i < intArr.size(); i = i+1){
if(intArr.get(i) < minValue)
{ minValue = intArr.get(i);
return minValue;


In your method declaration, change:
...(ArrayList intArr) { to ...(ArrayList<Integer> intArr) {.
This will make the elements in intArr Integers and not an Objects. To learn more about generics in java, look at The Java™ Tutorials on Generics.