java - Quick one: clarity or short code? -
OK, like I did a quick promise, so we go here:
The piece is found in in
in.split ("");
to mark the string, so I get all the characters separately and then remove those people I do not want, and currently it looks like this:
list & lt; String & gt; Op = new array list & lt; String & gt; (Arrays.asList (in.split (""))); Op.removeAll (removable); Operators = op.toArray (new string [op.size ()]);
Where op
is my temporary variable to delete. Is there any way to put it in one line? And if there (pls tell me how, i was thinking for some time and i thought that there is not because removeAll ()
boolean gives) - should it be done or should i Should It Be Easy To Read?
If you want to remove the alphabet, regex will be a better option than an array of string characters, and You do not need to use a list to process it.
Remove the string = "[a-zA-Z0-9]"; String operators = in.replaceAll (removable, "");
This gives you a string of non-removable characters.
If there is a removable archive, you can turn it back into a string.
String Reggae = "[" + (Removable. Stream.) (Collectors. Joining ())) + "]"; String operators = in.replaceAll (regex, "");
You can inline it to create a liner to regex
.
If you want to remove words, you need Java 8 to stream it in a serial (unless you write a method to do that, Line)
list & lt; String & gt; Operator = stream.f (insupeit (""). Filter (S ->! Removable seamants) .collect (collectors list);
However, to make it readable, you can still end up using three new lines. ;)
Comments
Post a Comment