I want to remove an element from the ArrayList whose length is equal to the number passed as an integer. My code is as follows. When run, the programs throws UnsupportedOperationException in the line when remove() method is used. Actually, it is a codingbat problem.
public static List<String> wordsWithoutList(String[] words, int len) {
List<String> list = new ArrayList<String>();
list = Arrays.asList(words);
for(String str : list) {
if(str.length() == len) {
list.remove(str);
}
}
return l;
}
(List<String>) Arrays.asList(words);