I wrote a program which is throwing ConcurrentUpdateException
, I am unable to understand this behavior, It should not through any exception as i have only single thread to work with and i have not taken any iterator.
What happens in, sorting ? Why it is throwing this exception ? Please explain.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Test {
public static void main(String[] args) {
List<Double> list1 = new ArrayList<Double>(Arrays.asList(3., 2., 0., 1., 2.));
List<Double> subList = list1.subList(0, 3);
Collections.sort(list1);
System.out.println(subList.get(0));
}
}