I want to perform a substring.equals("\n")
. In the code below, I take the last character and check if it is a newline.
String substring = nextResult.length() > 1 ? nextResult.substring(nextResult.length() - 1) : nextResult;
return substring.equals("\n") ? /* do stuff */ : /* do other stuff */;
I take only the last character because Java takes \n
as one char
. However, from what I see, substring.equals("\n")
returns true
for whitespaces (" "
), and I think tabs (\t
). Is that so?
How can I correctly check if the end of a string is a newline, or at least if the string is a newline?