How do I compare strings with Java Scanner input values?

Asked 2 years ago, Updated 2 years ago, 130 views

I'm sorry to ask you a question as soon as I signed up.

System.out.println(Inp.nextLine() == "Admin");

In the code above, no matter how I give you the input value, you get the false value, and you get the input value and the string How should I compare to get Boolean as true when I input Admin?

java compare

2022-09-22 08:47

1 Answers

The equals method must be used for string (content) comparison.

== compares the address values.

"Admin".equals(Inp.nextLine())


2022-09-22 08:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.