I have three ArrayLists:
One is used for storing user input in the order they were entered, located in the main class.
Second one is exactly the same as the first one, but it is passed into a method called remTrip
to be copied and will return the result.
Third one is list1
in the code below, which is the one being processed.
public static ArrayList<String> remTrip( ArrayList<String> a){
//code here
ArrayList<String> list1 = a;
Collections.sort(list1);
//code to remove triplicates from the list and returns the result
}
I wanted to keep the first ArrayList<String>
in the same order it was (i.e. {"dog", "cat" , "tiger", "cat", "cat"}
), but apparently the Collections.sort()
sorts all of the ArrayLists.
How do I sort only one of the list and not the others?