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?

[930 byte] By [ADC161178a] at [2007-11-27 2:09:09]
# 1
From the documentation for the Arrays.asList() method:"Returns a fixed-size list backed by the specified array."Given that, are you surprised that the remove() method is not supported by that list?
DrClapa at 2007-7-12 1:59:15 > top of Java-index,Core,Core APIs...