-
args[0] == "literal"
I'm taking arguments from the command line, and I'm comparing them in if else statments to find certain arguments.
Example:
java myProg -arg1 subArg
then I'll have for (int i=0; i<args.length; i+=2) {
if (args[i] == "-arg1") { do something } else if (...
else { defualt something }
I always get the default something. args is a String array in my main method call. Problem comparing string literals with string array?
NOMAD
-
Its a problem with comparing all strings this way...
Code:
if (args[i] == "-arg1")
== , when used with objects, compares the object pointers, ie - are they pointing to the same object. Use the equals() method instead.
Code:
if (args[i].equals("-arg1"))
:)
-