Simple Java question about command line arguments

Edit: figured it out myself, args[0] == "one" should be args[0].equals("one")

public Class Test{
public static void main(String[] args) {
System.out.println(args[0]);
if(args[0] == "one")
{ System.out.println("onetest");
}
}
}

it compiles and everything, and when I type
> java Test one
into the command line, this is my output
> one

what am i doing wrong, and why isn't it displaying "onetest" it printed "one" because args[0] is equal to "one," but somehow args[0] isn't "one" because it doesn't print "onetest" ???

expected output is
> one
> onetest

Respuesta :

Answer:

Simple Java question about command line arguments

Edit: figured it out myself, args[0] == "one" should be args[0].equals("one")

public Class Test{

public static void main(String[] args) {

System.out.println(args[0]);

if(args[0] == "one")

{ System.out.println("onetest");

}

}

}

it compiles and everything, and when I type

> java Test one

into the command line, this is my output

> one

what am i doing wrong, and why isn't it displaying "onetest" it printed "one" because args[0] is equal to "one," but somehow args[0] isn't "one" because it doesn't print "onetest" ???

expected output is

> one

> onetest