I would like to check that string that is a filename contains a illegal argument from the ILLEGAL_CHARACTERS
. Simply I could use for loop, but I want to do this by Streams.
My code:
package shared;
import java.util.Arrays;
public class Validator {
private static final Character[] ILLEGAL_CHARACTERS =
{'/','\n','\r','\t','\0','\f','`','?','*','\\','<','>','|','\"',':'};
public static boolean fileNameIsValid(String fileName) {
return Arrays.stream(ILLEGAL_CHARACTERS).anyMatch(fileName::contains);
}
}
Problem is in contains method cuz It needs a CharSequence
instead of char
. Is there any way to do this by stream without changing Character[]
type to String[]
?