What method is used to compare two strings ?

Answers were Sorted based on User's Feedback



What method is used to compare two strings ?..

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

What method is used to compare two strings ?..

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

What method is used to compare two strings ?..

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

What method is used to compare two strings ?..

Answer / ravikiran(aptech mumbai)

by overriding the compare method of comparator class

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More Core Java Interview Questions

What are nested classes in java?

0 Answers  


What is primitive array?

0 Answers  


What are the special characters?

0 Answers  


Is empty .java file name a valid source file name?

0 Answers  


What is a qualifier in a sentence?

0 Answers  






What must a class do to implement an interface in java programming?

0 Answers  


What is the difference between jdk and jre?

0 Answers  


Difference between abtsract & final

1 Answers   Nous,


What is static in java?

0 Answers  


Is it possible to write a regular expression to check if string is a number?

0 Answers  


What an i/o filter?

0 Answers  


What are the differences between string and stringbuffer?

0 Answers  


Categories