Why does collections.sort throw unsupported operation exception while sorting by comparator in Java? -


My code is used to sort a list with a predefined order. In the list of items, Has been mentioned.

  final list & lt; String & gt; Gold with items = myMethod.getSortedItems (); & Lt; String & gt; Plainethimlist = myMethod2.getAllItems (); Final comparison & lt; String & gt; Comparator = new comparison & lt; String & gt; () {Compare the public int (string str1, string str2) {return order of (str1) - orderOf (str2); } Private Ent Order of (String Name) {Return (Item Safar)). Indexof (name); }}; collection. Support (plain ecimalist, comparator); Return simple IDLost;  

throws the above code

  Reason by: java.lang.UnsupportedOperationJava.util. Select $ $ unassailable $ 1.set (archive .java: 1244) at Java.util.Collections.sort (archive .java 2821)  

I'm sure why the list is unthinkable please Help me

The list is not revised, obviously your client method is making an incompetent list (for example < Code> collection # unbearably listed etc.) Just make a modifying list before sorting:

  list & lt; String & gt; Modified Liquid = New Array List & lt; String & gt; (Unmodile List); collection. Source (revised list, comparator);  

Comments