Possible Duplicate:
How do I compare strings in Java?
Java string comparison?
import java.util.*;
public class whatever
{
    public static void main(String[] args)
    {
        Scanner test = new Scanner(System.in);
        System.out.println("Input: ");
        String name = test.nextLine();
        if (name == "Win")
        {
            System.out.println("Working!");
        }
        else
        {
            System.out.println("Something is wrong...");
        }
        System.out.println("Value is: " + name);
    }
}
The code above is pretty self-explanatory. I'm assuming == can only be used for numbers? I want "Working!" to be printed.
== compares objects by reference.
To find out whether two different String instances have the same value, call .equals().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With