0

Can anyone help me with this?

I am getting Caused by: java.lang.IndexOutOfBoundsException: Invalid index 14, size is 14 list is an ArrayList<String> of size 11 and result is a custom ArrayList of size 20 if (list != null) { String[] names = new String[list.size()]; for (int i = 0; i < list.size(); i++) { names[i] = list.get(i); } for (int k = 0; k < result.size(); k++) { for (int j = 0; j < names.length; j++) { if (result.get(k).getNewspaperName().contains(names[j])) { result.remove(k); } } } }

26th Aug 2019, 7:05 PM
Ghost rider
1 Answer
+ 3
In for loops use i < list.size()-1 and names.lenght()-1 Since index of array and string starts at 0, final element or char in string will be at index size-1
26th Aug 2019, 8:38 PM
Elva
Elva - avatar