-6

So I'm currently learning Java & have been watching thenewboston but I'm wanting to see if what the user types is x then do x hopefully that makes sense.

If you could leave an example it would help me a lot.

Pshemo
  • 122,468
  • 25
  • 185
  • 269
Aprexo
  • 11
  • 4

1 Answers1

0

Use the string1.equals(string2) method:

String expected = "hello, world";
if(input.equals(expected)){
    //Do something
}

This method returns true if the two strings are equal and false if they are not. You cannot just use == as this compares the pointers/references of the strings, and not the strings' content.

Edit: You can read input by using a Scanner.

Blubberguy22
  • 1,344
  • 1
  • 17
  • 29