How do I get rid of the blanks on the list? Spaces have become list components, so how do I get rid of them all?
Result value
['[', ', '\n', '\r', '', '\n', '\r', '', '', '\n', '\r', '', ', '\n', '\r', '', '', '\n', '\r', ']
What should I do if I want to get rid of all the gaps in the list?
list remove whitespace del
You didn't write down your language, Typically, you can solve it using regular expressions.
//Java Example
List<String> list = new ArrayList<>();
list.add(" ");
list.add("\n");
list.add("\r");
list.add("\t");
System.out.println(list.size()); //Output: 4
list.removeIf(n->n.matches("\\s"); // Find blank characters such as tabs, line breaks, spaces, and so on.
System.out.println(list.size(); //output: 0
© 2024 OneMinuteCode. All rights reserved.