I have been trying to remove null entries from an ArrayList without success.
First, I store all words from a file into an ArrayList using specific delimiters (punctuation and whitespace).
Then I attempt to remove null entries from the ArrayList.
When I print the whole list, the null entries are still there.
How can I solve this?
ArrayList<String> words = new ArrayList<String>();
while (scanner.hasNext()) {
words.add(scanner.next());
}
for (int i = 0; i < words.size(); i++) {
if (words.get(i) == null)
{
words.remove(i);
}
}
Example of current output:
[10, years, , , 3, Lec, , , 3, Lab, , , , Coordinating, Board, Academic, Approval, Number, 1102015707, ]
Example of desired output:
[10, years, 3, Lec, 3, Lab, Coordinating, Board, Academic, Approval, Number, 1102015707]