lets say my words Array is words={"a","the","in","if","are","it","is"} and my ArrayList contains strings like this {"a table is here", "books are sold","if it is readable"}. i want to remove all the words of array from the arrayList. expected output would be ArrayList as {"table here","books sold","readable"}.
i have tried this so far :
public static void main(String[] args) {
String[] words = {"a","the","in","if","are","it","is"};
List<String> wordList = new ArrayList<String>(Arrays.asList(words));
String[] tArray = {"a table is here", "books are sold","if it is readable"};
List<String> list = new ArrayList<String>(Arrays.asList(tArray));
for (int i = 0; i < list.size(); i++) {
String[] tArrays = list.get(i).split(" ");
List<String> line = new ArrayList<String>(Arrays.asList(tArrays));
for (int c = 0; c < wordList.size(); c++) {
if (wordList.get(c).equals(line.get(i))) {
line.remove(i);
i--;
break;
}
}//end for
list.set(i, String.join(" ", line));
}//end for
for(String string : list)
{
System.out.println(string);
}
}
but not giving the expected output. instead gives an error "java.lang.ArrayIndexOutOfBoundsException: -1"