(I assume that args0
and args1
holds Strings with same value)
args0.intern()
will check if String pool already contains String with same value as String from args0
.
- If pool contains such String reference to it will be returned, if not new String with same value as
args0
will be created, placed in pool reference to it returned.
after
args0.intern();
args1.intern();
args0
and args1
still hold Strings used in command line so they are different from Strings in pool.
To change it try maybe
args0 = args0.intern();
args1 = args1.intern();
now args0 = args0.intern();
will place "put" String from args0
in pool update args0
to hold that String. After args1 = args1.intern();
intern will see that pool contains same string (placed earlier with args0.intern()
) so will just return reference to it and store it under args1
.
Now if(args0 == args1)
should be true
because both references hods the same String object.