I am trying to reverse an unmodifiable list. However i have tried to achieve it but Is it possible to update or reverse and unmodifiable list? I know we can do it with Google Immutable List
import java.util.*;
public class ImmutableList
{
public static void main(String args[])
{
String[] mylist = {"Apple","Orange","Mango","Kiwi","Banana"};
List reverselist = new ArrayList();
List<String> strList = Arrays.asList(mylist);
List<String> unmodifiableList = Collections.unmodifiableList(strList);
for(int i=unmodifiableList.size();i>0;i--)
{
reverselist.add(unmodifiableList.get(i-1));
}
List<String> reverse = Collections.unmodifiableList(reverselist);
System.out.println(reverse);
}
}
In the above program I am just traversing in unmodifable list from back and putting them in an array after that adding that array to new unmodifiable list. Can we do it in better way in terms of optimisation?