The comments in the program below are self explanatory and should help you figure out the subtleties of new object creation and the == operator versus equals() method.
public class CompareQuestion { public static void main(String[] args) { String s1 = new String("A"); //not recommended, use String s1 = "A" String s2 = new String("A"); //not recommended, use String s2 = "A" //standard: follows the == and equals() rule like plain java objects. if (s1 == s2) { //shallow comparison, never reaches here System.out.println("references/identities are equal"); } if (s1.equals(s2)) { //deep comparison, this line is printed System.out.println("values are equal"); } //variation: does not follow the == and equals rule String s3 = "A"; //goes into a String pool. String s4 = "A"; //refers to String already in the pool. if (s3 == s4) { //shallow comparison, this line is printed System.out.println("references/identities are equal"); } if (s3.equals(s4)) { //deep comparison, this line is also printed System.out.println("values are equal"); } } }
ReplyDeleteThanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write.
Thanks for sharing !
tanki online 2 | 2048 game online
Ever since their invention computers have become an essential part of our lives. We use computers and computer related devices in everyday life. They have acquired supreme importance in every walk of life.
ReplyDeleteStartPoint
It's Really A Great Post. Looking For Some More Stuff
ReplyDeleteBest Oracle SQL Training institute in Bangalore
Best Java Training in Bangalore
Hi There,
ReplyDeleteWhat a brilliant post I have come across and believe me I have been searching out for this similar
kind of post for past a week and hardly came across this.
I have two methods and they do almost same thing, but at some most inner nested level one of method have additional command.
Java Code:
method2(){
... same code ...
for {
... same code ...
if{
... same code ...
}
}
}
Follow my new blog if you interested in just tag along me in any social media platforms!
Shukran,
Munni
Ayam Bankok
ReplyDeleteThanks for sharing a worthy information. This is really helpful. Keep doing more.
ReplyDeleteSpoken English Classes in Chennai
Spoken English in Chennai
Top 10 Spoken English Classes in Chennai
Best IELTS Coaching in Chennai
IELTS Coaching Centre in Chennai
English Classes in Mumbai
English Speaking Classes in Mumbai
Best IELTS Coaching in Mumbai
IELTS Coaching in Mumbai
Spoken English Classes in Anna Nagar
I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work... Kopar at Newton Condo
ReplyDeleteThe most important thing that a new programmer needs to know is that the "Learn Programming in 24 hours" sort of books are simply not true. A more accurate title would be "Learn Programming in 10,000 hours".best ergonomic chair
ReplyDeletedfgh
ReplyDeleteHere at this site really the fastidious web design studio material collection so that everybody can enjoy a lot.
ReplyDeleteYou can do this by finding the module in the WordPress Module Catalog and checking the similarity confine the correct hand section. error establishing a database connection
ReplyDeleteIt will be essential that each progression of advancement stake its natural incentive to society via flawlessly sticking to social, environmental, and financial boundaries. excel vba training london
ReplyDeleteBut the web developers use a variety of add-on modules to write modern web applications in Python. While writing web applications in Python, programmers have option to use several high-level web frameworks unindent does not match any outer indentation level python
ReplyDeleteI got too much interesting stuff on your blog. I guess I am not the only one having all the enjoyment here! Keep up the good work. targonca szállítás Debrecen Europa-Road Kft.
ReplyDelete