How to compare 2 strings in an if statement? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to compare 2 strings in an if statement?

How to compare two strings to test to see if user typed the correct string

15th Dec 2016, 4:09 PM
CYB
CYB - avatar
4 Answers
+ 5
Try this : if (String1.equals(String2)) { System.out.println("They match"); else {System.out.println("They not match");}
15th Dec 2016, 5:02 PM
TARIK AIT LAABIDI
TARIK AIT LAABIDI - avatar
+ 1
Thanks!
15th Dec 2016, 9:01 PM
CYB
CYB - avatar
0
if "string1"=="string2": Try this. My experienced with java is limited, but I think this should work.
15th Dec 2016, 4:45 PM
Jacob Davis
Jacob Davis - avatar
- 1
I think this works If " string2 " =="string1" And ....
17th Dec 2016, 9:06 PM
Saeid Khajerezaei yazdi
Saeid Khajerezaei yazdi - avatar