java - Remove In Range in an ArrayList -


i have following requirements write java method. write method called removeinrange accepts 4 parameters: list of integers, element value, starting index, , ending index. method's behavior remove occurrences of given element appear in list between starting index (inclusive) , ending index (exclusive). other values , occurrences of given value appear outside given index range not affected.

for example, list (0, 0, 2, 0, 4, 0, 6, 0, 8, 0, 10, 0, 12, 0, 14, 0, 16), call of removeinrange(list, 0, 5, 13) should produce list (0, 0, 2, 0, 4, 6, 8, 10, 12, 0, 14, 0, 16). notice zeros located @ indices between 5 inclusive , 13 exclusive in original list (before modifications made) have been removed. have written method follows:

public static void removeinrange(list<integer> list,int value,int beg,int end) {     beg=new integer(beg);     //integer b=beg;     int count=0;     list.sublist(5, 13); /*  for( integer b:list.sublist(beg, end))      {         if(list.get(b)==value)         list.remove(b);     }     */     iterator<integer> iter = list.sublist(beg, end).iterator();     int i=iter.next();     while(iter.hasnext())     {         if (iter.next().intvalue()==value)          {             iter.remove();          }      }      system.out.println(list); } 

however, method gives me error exception in thread "main" java.lang.unsupportedoperationexception.i want hints or suggestions how can change method avoid exception?

one fix create new type of list support removal such linkedlist, copy elements list linkedlist, perform operation , return linkedlist.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -