There seems to be a difference between main(String[] args)
and other string arrays that i can not figure out, my example.
public class TestArgs
{
public static void main(String[] args) {
String[] x = {"1","2","3"};
System.out.print( x[2] == "3" );
System.out.print( args[2] == "3" );
}}
I run this program as:
java TestArgs 1 2 3
I would expect the output to be "truetrue" but instead I get "truefalse"
Could someone please tell me what the difference is, or am I just doing something really stupid...
Answer
in java, you have to use "test".equals("test")
to test for string-equality ;)
strings are objects and the objects are not the SAME, they just have the same VALUE
No comments:
Post a Comment