Android String null check is weird

Asked 2 years ago, Updated 2 years ago, 23 views

String a;

a = "123";

if(a == null) { Output string null }

I did it like this I put the string "123" in the string.

If I check the null in the next line, it says null, is there something wrong?

Can't I null-check a string like this in Java?

Thank you^

^

android

2022-09-22 10:40

1 Answers

Something must have gone wrong. Look at the results below.

jshell> String a;
a ==> null

jshell> a = "123";
a ==> "123"

jshell> a == null
$3 ==> false


2022-09-22 10:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.