0

Here is the code I am using for the output in the end

public static String processMessage(String input)
{
    String[] token = input.split(" ");
    if (token[0] == "add")
        return "yeah its a match";
    else
        return "not a match";
}

Here is the image of my test

enter image description here

Does anyone know what could be wrong?

Evan
  • 2,405
  • 3
  • 20
  • 24

1 Answers1

1

if (token[0] == "add")

A String is an object, not a primitive data type. For that reason you should be using the object comparison method .equals()

e.g. if token[0].equals("add")

Also, if this is user input then consider .equalsIgnoreCase()

JamoBox
  • 764
  • 9
  • 23
  • That works, sorry if it's a duplicate question. Will check-mark this post when I can (9 minutes) – Evan Nov 10 '13 at 00:25