the == operator ensure whether the memory location of both objects are same or not!
while the " String " and "String" both creates different memory addresses!
i think thats because == sees if two refernces are pointing to same object...in this case they will both point to same string in the string pool but on the heap they are two different objects. Rafael's code will do.