when I run it
java ArgIt x
it does not print x2.
Why is that? why is it that when the string passed as an argument to the program is not ==??? does the args have a different value?
why is then "x"=="x" when args is not equal (==) to "x" ?
Basically, you should never use == to compare Strings. You should always use equals(). However, because of the way the String pool is managed, == will sometimes give the right results. Line 5 is an example - using String literals will result in the same object being used, so == does what you expect. But this behaviour should never be relied on, and line 4 shows an example why.