I want to sort a list of numbers without change the original list. So this is what I did:
public double median(){
//first,sort the list
LinkedList<Double>sorted = entries;
Collections.sort(sorted); ...
entries is another LinkedList that I would like to have it unsorted. I created a new LinkedList named sorted for not changing the original entries list. The sorted list is only used for this double function. However everytime when I call the function it still sorts the entries list.
How can I sort it without changing the original list?
What I've done so far:
LinkedListsorted = entries;
2.
LinkedList<Double>sorted = new LinkedList<Double>();
Collections.copy(sorted,entries);
3.
LinkedList<Double>sorted = new LinkedList<Double>();
for(int i=0;i<entries.size();i++){
sorted.add(entries.get(i));}
And none of them are working properly. They do the sort work, but they changed the entries list which I don't want to change.
Thanks everyone. The problem is now solved. I copy pasted them to another software and paste back and it now works properly. I still can't understand why though.