0

I want to check it the first input argument is operator "+"

below is the code

if (args[0] == "+") {
    System.out.println("good");
} else {
    System.out.println("invalid expression");
}

but it always return false. something wrong with the code?

Will
  • 583
  • 10
  • 23

1 Answers1

2

You should compare strings using str.equals(..) method and not ==, which compares object adresses.

if (args[0].equals("+")) {
  :
}
MaxZoom
  • 7,320
  • 5
  • 27
  • 43
user2494817
  • 697
  • 4
  • 12