1: Byte b1 = new Byte("127"); 2: 3: if(b1.toString() == b1.toString()) 4: System.out.println("True"); 5: else 6: System.out.println("False"); The above code will print False? Why? In line 3, if replace "==" by equals() method, will output change? Thanks. Luk
Hi Luk By the "toString" method, two objects are created which are different , so the answer is FALSE. If you replace '==' by 'equals' then answer is true, because String class overrides the equals methods and compare the contents of String objects. Hope this clarifies.
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop