say, I made an arraylist in (public class class1(String args[]))
static List<Double> list1 = new ArrayList<Double>();
then I pass this arraylist to a function in (public static void main(String args[]))
biggestvalue(list1);
this is the function for example:
public static double biggestvalue(List<Double> list){
Collections.sort(list);
return list.get(list.size()-1);
}
I pass it into a function so that hopefully it will only sort list but not list1, but then list1 gets sorted as well, and I do not understand why that is. Therefore, please explain to me why that is, and what solutions to this error are out there?
Collections.max(collection)is for!