In second example String is also an Object since all classes subclass Object and you can check if they are ==.
In first example you compare String to StringBuilder which are different classes and neither is subclass of the other so the operator fails.