I tried the below, but Eclipse throws an error for this.
while((s.charAt(j)== null)
What's the correct way of checking whether a character is null
?
Check that the String
s
is not null
before doing any character checks. The characters returned by String#charAt
are primitive char
types and will never be null
:
if (s != null) {
...
If you're trying to process characters from String
one at a time, you can use:
for (char c: s.toCharArray()) {
// do stuff with char c
}
(Unlike C
, NULL
terminator checking is not done in Java.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With