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

Why is inheritance used in java?

0 Answers  


How to prevent to create multiple objects of a java class?

3 Answers   ASD Lab, TCS,


class A { class B { psvm(String args[]) { } } } if the prg saved in A.java whats the o/p?

7 Answers   HCL, TCS,


What are serialization and deserialization?

0 Answers  


What is an empty string in css?

0 Answers  






What is the output of the below java program?

0 Answers  


What are the features of java?

0 Answers  


what is the use of custom tags? with example?

1 Answers   Photon,


Hi friends am new to java. I read jar file means collection of java files. For executing struts application what are the necessary jar files. " struts.jar " file contains what. can u explain

0 Answers  


Can private method static?

0 Answers  


Which package is used for pattern matching with regular expressions?

0 Answers  


My interview asked what is dynamic variable in java and where we use them.

2 Answers   IBM,


Categories