There is an ArrayList, which consists of Strings. How can I remove those elements, the lines in which begin with five spaces?

    1 answer 1

    Option 1:

    Iterator<String> itr = list.iterator(); while (itr.hasNext()) { String s = itr.next(); if (s.startsWith(" ")) { itr.remove(); } } 

    Option 2:

     list = list.stream() .filter(s -> !s.startsWith(" ")) .collect(Collectors.toList());