java - Collection.sort(arraylist) in a function sorting another arraylist -
Say, I have created an array list in (public square class 1 [string array [])
<Then I will assign this array to a function (public constant Passing zero main (string error [])
biggest value (list1);
This is the function for example:
Public Stable Double The Largest Value (List & quot; Double & gt; Su Chi) {Collections.sort (list); return list.get (list.size () - 1);}
I pass it in a function so that it is expected Will list only the list but not list 1 but list 1 is also sorted, and I do not understand why this is why, please explain to me why this is, and what is the solution to this error?
In the context of only list
when you pass it as argument In areas so both list indicates
and list1
same List
.
A good rule of thumb is not to modify the object passed in a method, so I will make a copy inside the method:
public stable double largest value (list & Lt; double & gt; list) {List & lt; Double & gt; Temp = new arreelist & lt; & Gt; (List); Collections.sort (Temporary); Return temp.get (temp.size () - 1); }
Comments
Post a Comment