Java String Comparison Methods.

Kumar Varma
Published on 09-Feb-2018 17:31:05
Java String class provides different comparison methods namely:The compareTo() methodThis method compares two Strings lexicographically. This method returns  a negative integer if current String object lexicographically precedes the argument string.  a positive integer if current String object lexicographically follows the argument  true when the strings are equal.Exampleimport ... Read More

How to get a substring of a particular string in Java. Explain with an example.

Abhinaya
Published on 09-Feb-2018 17:42:48
The substring(int beginIndex, int endIndex) method of the String class. It returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.ExampleLive Demoimport java.lang.*; public ... Read More

Case sensitive string comparison in Java.

Moumita
Published on 09-Feb-2018 17:38:58
You can compare two strings using either equals() method or compareTo() method.Where, The equals() method compares this string to the specified object.The compareTo() method compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings.These two methods compare the given strings with respective ... Read More

How to check Palindrome String in java?

Ayyan
Published on 09-Feb-2018 17:38:15
StringBuffer provides a method with name reverse() one way to check for a palindrome isCreate a StringBuffer object by passing the required string as a parameter to the constructor.Reverse the contents of the object using the reverse() method.Convert the StringBuffer object to Sting using the toString() method.Now, compare the String and the ... Read More

What is the difference between StringBuffer and StringBuilder in java?

Manikanth Mani
Published on 09-Feb-2018 17:34:51
The StringBuffer and StringBuilder classes are used when there is a necessity to make a lot of modifications to Strings of characters.Unlike Strings, objects of type StringBuffer and String builder can be modified over and over again without leaving behind a lot of new unused objects.The StringBuilder class was introduced as of ... Read More

String compare by compareTo() method in Java

Sravani S
Published on 09-Feb-2018 17:12:23
The compareTo() method compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings. The character sequence represented by this String object is compared lexicographically to the character sequence represented by the argument string.The result is a negative integer if this String object lexicographically ... Read More

Java String equals() method.

Manikanth Mani
Published on 09-Feb-2018 17:21:02
The equals() method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.Example Live Demopublic class Sample{    public static void main(String []args){       ... Read More

Difference between == and equals() method in Java.

Alankritha Ammu
Published on 09-Feb-2018 17:18:11
The equals() method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.Example Live Demopublic class Sample {    public static void main(String []args) {   ... Read More

Compare two strings lexicographically in Java.

Fendadis John
Published on 09-Feb-2018 16:24:14
The compareTo() method of the String class. This method compares two Strings lexicographically. The comparison is based on the Unicode value of each character in the strings. The character sequence represented by this String object is compared lexicographically to the character sequence represented by the argument string. This method returnsa ... Read More

How to check if two strings are equal in Java?

Anjana
Published on 09-Feb-2018 17:12:50
You can check the equality of two Strings in Java using the equals() method. This method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this ... Read More
Advertisements