UnsupportedOperationException at java.util.AbstractList.remove
Hi,
The problem is that I keep getting this
"UnsupportedOperationException at java.util.AbstractList.remove"
exception.
I am not using ArrayList anywhere in my program.
I have 2 lists, I want the intersection of these 2 lists.
The error occurs at first remove the program encounters. So it can't remove this item. Both lists have at least one String item (I checked using System.out ...).
This is the code:
public List<String> isfreq(List<Edge> currsubg, Edge newEdge) {
List<Edge> csg = currsubg; //Edge is some datatype
Edge edge = newEdge;
List<String> namesUntilNow = edge.getListGraphNames(); //returns list of String
List<String> newNames = new LinkedList<String>(); //emptylist
//Take intersection of an array of Edge (each having a list of String)
for (int i = 0; i < csg.size(); i++){
Edge temp = csg.get(i).cloneIt();
List<String> namesThisEdge = temp.getListGraphNames();
newNames = listIntersection(namesThisEdge, namesUntilNow);
namesUntilNow = newNames;
}
return namesUntilNow;
}
//Take intersection of two string lists
public List<String> listIntersection(List<String> arrayOne, List<String> arrayTwo){
List<String> one = arrayOne;
List<String> two = arrayTwo;
List<String> out = new LinkedList<String>();
int test = 0;
while (!(one.isEmpty() || two.isEmpty())){
test = one.get(0).compareTo(two.get(0));
//Equal
if (test == 0){
out.add(one.get(0));
one.remove(0); <-- error occurs directly here
two.remove(0);
}
...
}
previously the one.remove worked just fine. listIntersection has not changed.
Any help would be greatly appreciated. Thanks.

