[answered] Comparising input strings (Java) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

[answered] Comparising input strings (Java)

I have an input (scanner.nextLine()) and I enter "ABC". Why does input=="ABC" return false?

25th Jan 2020, 2:01 PM
C. Scheler
C. Scheler - avatar
2 Answers
+ 1
Use s1.equals(s2) to compare strings: input.equals("ABC')
25th Jan 2020, 2:12 PM
unChabon
unChabon - avatar
0
Because String in Java is a reference type, this means that when you use the String in your program, you are actually using its reference. "ABC" == "ABC" actually compares the references of the strings.
25th Jan 2020, 5:40 PM
Seb TheS
Seb TheS - avatar