Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

where is .equals() method and how is it different from ==
operation <giving some confusing implementation> Is hashing
related to these?

Answer Posted / namita

equals() method is used for comparison. it copares the
content whereas == is used to compare the references.

if the hashcode value is same for two objects equals()
method will return true. but in case of == it is not the
case.

Try following code

String str="Java";
String str1="Ja";
String str2="va";
String str3=str1+str2;
String str4 = new String("Java");
String str5 = str4;
String str6 = new String("Programming");
String str7 = new String(str6);
System.out.println(str3);
System.out.println("str "+str.hashCode());

System.out.println("str3 :- "+str3.hashCode());
System.out.println("str4 :- "+str4.hashCode());
System.out.println("str5 :- "+str5.hashCode());
System.out.println("str6 :- "+str4.hashCode());
System.out.println("str7 :- "+str5.hashCode());


if(str==str3)
System.out.println("str and str3 are equal(==)");
else
System.out.println("str and str3 are not equals
(==)");
if(str.equals(str3))
System.out.println("str and str3 are equals(.equals
())");
else
System.out.println("str and str3 are not equals
(.equals())");


if(str4==str5)
System.out.println("str4 and str5 are equal(==)");
else
System.out.println("str4 and str5 are not equals
(==)");
if(str.equals(str3))
System.out.println("equals");
else
System.out.println("not equals");


if(str6==str7)
System.out.println("str6 and str7 are equal(==)");
else
System.out.println("str6 and str7 are not equals
(==)");
if(str.equals(str3))
System.out.println("equals");
else
System.out.println("not equals");

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is parsing a sentence?

997


How does a for loop work?

942


What is unicode used for?

1083


what is use of functional interface in java 8?

975


What are "methods" and "fields"?

970


How do you access command-line arguments within the code?

1003


According to java operator precedence, which operator is considered to be with highest precedence?

1034


How do you use parseint in java?

936


What is string builder?

841


What type of variable is gender?

932


How many days will it take to learn java?

883


Explain the significance of listiterator.

1023


If you are given the name of the function at run time how will you invoke the function?

1078


What do you understand by synchronization?

985


What is stack explain?

929