I'm trying to remove all whitespaces from a string. I've googled a lot and found only replaceAll()
method is used to remove whitespace. However, in an assignment I'm doing for an online course, it says to use replace()
method to remove all whitespaces and to use \n
for newline character and \t
for tab characters. I tried it, here's my code:
public static String removeWhitespace(String s) {
String gtg = s.replace(' ', '');
gtg = s.replace('\t', '');
gtg = s.replace('\n', '');
return gtg;
}
After compiling, I get the error message:
Error:(12, 37) java: empty character literal
Error:(13, 37) java: empty character literal
Error:(14, 37) java: empty character literal
All 3 refer to the above replace()
code in public static String removeWhitespace(String s)
.
I'd be grateful if someone pointed out what I'm doing wrong.