I have coded below, i dint know what is wrong but validDatesIterator.remove() is giving me UnsupportedOperationException exception. Using java 1.6
List<Integer> validDates = Arrays.asList(26,27,28,1,2,3,4);
List<Integer> daysToBeRemoved = Arrays.asList(1,2);
Iterator<Integer> validDatesIterator = validDates.listIterator();
while(validDatesIterator.hasNext()) {
Integer curValue = validDatesIterator.next();
for(Integer dayToRemove:daysToBeRemoved) {
if(curValue.equals(dayToRemove)) {
validDatesIterator.remove();
break;
}
}
}
Also When i debug valid dates(curValue initially it gives 27, instead 26) is starting with element 27, not 26.
May be a duplicate question, but searched a lot, dint find kinda of this. Please help.
Arrays.asList
returnsArrays.ArrayList
, aList
implementation that doesnt support the removal of elements. Use