public static void main(String[] args) {
    String OptionId = "111, 112, 113, 114, 115";
    List<String> fullList = Arrays.asList(OptionId.split(","));
    List<String> values = new ArrayList<String>();
    System.out.println("fullList: " + fullList.toString());
    List<String> subItems = fullList.subList(0, 3);
    System.out.println("subItems: " + subItems);
    for (String s : fullList) {
        String strs[] = new String[2];
        if (subItems.contains(s) 
               || subItems.contains(strs[0]) 
               || subItems.contains(strs[1])) {
            values.add(s);                      // save the value to a list
        }
    }
    System.out.println("values: " + values);
    fullList.remove(values);
    System.out.println("fullList: " + fullList);
}
As per my knowledge, the final full list should have only [114, 115]. But its not removed the items present in the sublist.
I have also tried the below code. fullList.removeAll(values);
But it throws the below error.
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.AbstractList.remove(AbstractList.java:161)
at java.util.AbstractList$Itr.remove(AbstractList.java:374)
at java.util.AbstractCollection.removeAll(AbstractCollection.java:376)
at com.tesco.rangeplan.client.Test.main(Test.java:32)
I need the output as below:
fullList: [114,  115]
 
     
    