using jdk 5 removing element from ArrayList runtime exception
import java.util.*;
class ListOfInts {
public static void main(String[] args) {
List aList = Arrays.asList(7,4,9,1,2);
int countOfRmvd;
countOfRmvd = removeLessThanFive(aList);
System.out.println(aList);
}
public static int removeLessThanFive(List aList) {
int count = 0;
for (Iterator it = aList.iterator(); it.hasNext(); ) {
if ( ((Integer)(it.next())).intValue() < 5) {
it.remove();
count++;
}
}
return count;
}
}
C:\jprog>javac ListOfInts.java
C:\jprog>java ListOfInts
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.AbstractList.remove(Unknown Source)
at java.util.AbstractList$Itr.remove(Unknown Source)
at ListOfInts.removeLessThanFive(ListOfInts.java:15)
at ListOfInts.main(ListOfInts.java:7)
Why is the code failing?

