I would like to add a little to voyager's answer:
Regarding strings
Statement input = ""; from the collection point matches the entry input = "abcde..."; , since none of the operators invalidates the instance of the input object, but both simply modify the contents of the input String variable. In addition, for accuracy and refinement, input = something" modifies the contents of input , and String input = ""; creates an instance of input .
If input == "", then 'if (input.isEmpty ()) would be true, but if (input == null) `would be false.
Regarding the garbage collection
Operator input = null; decreases the reference count for this particular instance of the object, which, if it is the last reference to input , then input will be marked for garbage collection, which will not happen deterministically by the AKA when the garbage collector gets to it. The case when input = null; not really an input flag for garbage collection, would be: if input also passed to the collection; until input is removed from the collection, it will keep the reference count from decrementing and therefore from garbage collection.
Hope this helps, and for someone else out there, please feel free to correct any errors, even if they are subtle.
-bn
bn.
source share