How to compare two strings ?

There are two ways to compare the two strings in java: 

 * using the == operator, * using the equals() method.

 For Example:String s1=new String(\"Hello!\");String s2=new String(\"Hello!\");if(s1==s2) System.out.println(\"Equal using == operator.\");elseif (s1.equals(s2))System.out.println(\"Equal using equals method.\");elseSystem.out.println(\"Not Equal.\");

More interview questions and answers
What are the primitive data types in Java ?
What is mean by a wrapper class ?
What is Garbage collection ?
What is mean by final class, methods and variables ?
What is mean by interface ?
What is the difference between an array and a vector ?
What is singleton class ?
What is constructor ?
What is casting ?
What is the difference between final, finally and finalize ?
What is mean by packages in java?
Name 5 calsses you have used ?
Name 2 classes that can store arbitrary number of objects ?
What is the difference between java.applet.* and java.applet.Applet ?
What is a default package ?
What is anonymous class ?
What is the use of an interface ?
What is a serializable interface ?
How to prevent field from serialization ?
What is the difference between throw and throws ?
Can multiple catch statements be used in exceptions ?
Is it possible to write a try within a try statement ?
What is mean by a Thread ?
What is mean by multi-threading ?
What is the 2 way of creating a thread ? Which is the best way and why?
What is the method to find if a thread is active or not ?
What is the difference between sleep and suspend ?
Can thread become a member of another thread ?
What are the three types of priority ?
Garbage collector thread belongs to which priority ?
What is the use of this ?
How can you find the length and capacity of a string buffer ?
How to compare two strings ?
What is the purpose of run-time class and system class?
What is the method used to clear the buffer ?
What is mean by Stream Tokenizer ?
What is serialization and de-serialisation ?
What is mean by Applet ?
How to find the host from which the Applet has originated ?
What is the life cycle of an Applet ?
How do you load an HTML page from an Applet ?
What is mean by getCodeBase and getDocumentBase method ?
What is the use of parameter tag ?
What is the difference between getAppletInfo and getParameterInfo ?
How to communicate between applet and an applet ?
What is mean by event handling ?
What are all the listeners in java and explain ?
What is mean by an adapter class ?
What are the types of mouse event listeners ?
What are the types of methods in mouse listeners ?
What is the difference between panel and frame ?
What is the default layout of the panel and frame ?
What is the difference between list and choice ?
What are the different types of Layouts ?
What is mean by CardLayout ?
What is the difference between GridLayout and GridBagLayout?
Which class has no duplicate elements ?
What is mean by Swing ?
What is the difference between an applet and a Japplet?
What are all the components used in Swing ?
What is mean by tab pans ?
What is the use of JTree ?
What is the use of JTable ?
What is mean by JFC ?
What is JAR file ?
What is mean by manifest files ?
What is two properties in Beans ?
What is the use of beaninfo ?
What are the interfaces you used in Beans ?
What are the classes you used in Beans ?
What is the difference between C++ & Java ?
What is the difference between Process and Threads ?
How will you initialize an Applet ?
What is the order of method invocation in an Applet ?
When is update method called ?
What is JNI ?
What is the base class for all swing components ?
Is there any tag in HTML to upload and download files ?
What is the Layout for ToolBar ?
How will you add panel to a Frame ?
What is the corresponding Layout for Card in Swing ?
What is light weight component ?
What is difference in between Java Class and Bean ?
Diff between Application and Applet ?
What is the use of Interface ?
Why Java is not fully objective oriented ?
What it the root class for all Java classes ?
What is the exact difference in between Unicast and Multicast object ? Where we will use ?
Why there are some null interface in java ? What does it mean ?
What is latest versions in JAVA related areas ?
What is mean by class loader ? How many types are there? When will we use them ?
public static void main - Explain?
What is difference between String & StringBuffer?
What is Wrapper class. Is String a Wrapper Class?
What is Default modifier in Interface?
Can abstract be declared as Final?
Can we declare variables inside a method as Final Variables?
How can a dead thread be started?
Can Applet have constructors?
What is Checked & Unchecked exception?