What method is used to compare two strings ?
Answers were Sorted based on User's Feedback
Answer / interviewall
If string a="aaaa"; and String b="bbbb";
we can compare them as
if(a.equals(b)) and get a boolean as a return type.
////////////////////////////////////////////////////////
We can also compare String as
a.compareTo("aaaa"); which gives 0 as output as they are
equal.
| Is This Answer Correct ? | 6 Yes | 3 No |
Answer / k.b.s.reddy
we can use a string function...
eg:
strcmp("string1","string2")
it return 0 if string1=string2
it return >0 if string1>string2
it return <0 if string1<string2.
value returned depends on anscii calues of strings...
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / suman
The == operator works on String object references. If two
String variables point to the same object in memory, the
comparison returns a true result.
The equals method compares the actual char content of two
strings. This method returns true when two String objects
hold char data with the same values.
| Is This Answer Correct ? | 4 Yes | 3 No |
Answer / ravikiran(aptech mumbai)
by overriding the compare method of comparator class
| Is This Answer Correct ? | 0 Yes | 2 No |
How to know the host from which Applet is originated?
what is the difference between Java Command Line and C command Line?
What is the difference between access specifiers and access modifiers in java? 16
Explain, java is compatible with all servers but not all browsers?
What are the two basic ways in which classes that can be run as threads may be defined?
Explain listiterator and methods in listiterator?
Does unicode support all languages?
When we will use an Interface and Abstract class?
What are the advantages of exception handling?
what is the swingutilities.invokelater(runnable) method for? : Java thread
What is the common usage of serialization? What exceptions occur during serialization?
what is use of session tracking ?with example?