What is the difference between a.Equals(b) and a == b?
Answer Posted / rajan
equals() method compares the state of an object i.e. it
compares the contents of the two objects.
but == compares the instance of the object i.e. it comparing
the identifier(references).
Ex:
public class Test2
{
public static void main(String args[])
{
// Create two equal but distinct strings
String a = new String(new char[]
{'h', 'e', 'l', 'l', 'o'});
String b = new String(new char[]
{'h', 'e', 'l', 'l', 'o'});
System.out.println(a==b);
System.out.println(a.equals(b));
// Now let's see what happens with the same tests
// with variables of type object
Object c = a;
Object d = b;
System.out.println(c==d);
System.out.println(c.equals(d));
}
}
Output is:
false
true
false
true
From the above example the String object is creating new
instances, so == compares the instances are equal are not.
equal() method compares the contents of a two object .
| Is This Answer Correct ? | 8 Yes | 4 No |
Post New Answer View All Answers
Why cyclomatic complexity is important?
Explain the advantages of passport authentication.
Explain State management in asp.net
What is server side routing?
Explain the use of resource manager class in .net.
How many types of session state management options available in asp.net?
Any one can tell how we store tiff format images in database and retrive from the database(need for tiff format only)
Explain the difference between the web config and machine config.
What are the Types of session management in ASP.NET
What is the asp.net mvc folder conventions? : asp.net mvc
Hello, Using Visual Studio 2005 (VB) I am working to create a Web Site implementing the following: Within a gridView I have placed a dropdownlist control with a DataSourceID="SDSLkupList". SDSLkupList is a sqlDataSource used to store a lookup list for dropdownlist translation from ID to text. SDSLkupList contains the translation text and other fields related to the dropdown selection ID. (Thought it would be efficient to get everything at the same time.) I would like to provide the user the ability to select from the dropdownlist and, based on the selection, use labels to list related columns stored on the SDSLkupList in separate gridView columns. I have read that SqlDataSources are not meant to be used for individual controls. Since SDSLkupList contains all related information, is there a way to do a find using the dropdownlist selectedValue? (I was not able to discover one.) Otherwise, what should I use? It would need to set the labels on the gridView DataRowBound event as well as the SelectedIndexChanged events. Has anyone done this? Any help would be appreciated. Thanks in Advance. Neal
Define viewstate in .net?
They mostly asked difference between versions of technologies
What is the purpose of asp.net?
What are session objects?