Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How do you compare two strings? any predefined method for
this?

Answer Posted / sumann

You can compare the values of 2 Strings by following
methods of String class:-
Eg:- String a="abc"; String b="abc";
1> .equals() method it will return a boolean value.
eg:- if(a.equals(b)) will return true.
2> .compareTo() method.If the two java strings are exactly
the same, the compareTo method will return a value of 0
(zero).
eg:- if (a.compareTo(b) == 0){
// this line will print
System.out.println("a and b strings are the same.")
}

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why do we use threads in java?

1166


What is a 16 bit word?

1068


Can we execute a program without main?

1073


How a string is stored in memory?

1075


What are nested classes in java?

1165


What is the difference between char and char *?

1143


How does system arraycopy work in java?

1180


What is the relationship difference the canvas class and the graphics class?

1110


What do you mean by scope of variable?

937


What is a parameter in a function?

1034


What are the differences between string and stringbuffer?

1175


What is subsequence of a string?

1149


What methodology can be employed to locate substrings inside a string?

998


Explain the importance of finally block in java?

1021


Can we use switch statement with strings?

1087