No idea why you would want to do this, but writing a method to do that isn't all that hard...
public static void printlnWithIgnores(String toPrint, Set<Character> ignore) {
for(char c : toPrint.toCharArray()) {
if(! ignore.contains(c)) {
System.out.print(c);
}
}
System.out.println();
}
As for that happening within a string because of a character literal, I'm not sure that it's possible. Some tests:
\b
(the backspace character) doesn't work
(char)127
(the delete character) doesn't work
That said, if your passwords can have backslashes (\
) in them, that can absolutely be a problem. \
in Java is used to denote a special character, with the following character. The string "nnn"
is just "nnn"
, but "n\nn"
is
n
n
Because \n
represents a newline, the third n is lost.
There are many specialty characters denoted like this, but more importantly your passwords really can't have \
in them without causing issues. Either you're getting an escape character if the following character if the following character with a backslash is legal (and \1
actually is), or it won't print if it's not legal.