Series: Strings

this series contains string, stingbuffer and stringbuilder related entries.

equals() equalsIgnoreCase() String Example

Comparing Strings with equals() equalsIgnoreCase() String. First and foremost important operation on strings is to compare whether two strings are same or not. There are three styles which the programmer should be well aware of when to use what. The styles are Using logical equals to (==) Using equals() and equalsIgnoreCase() Using lexicographical order, compareTo() …

equals() equalsIgnoreCase() String Example Read More »

toLowerCase() String Example

java.lang.String class comes with toLowerCase() String method to convert all uppercase letters into lowercase in the string. After modification, a new string is returned with all the conversions. The signature of toLowerCase() String is given as defined in Java API. public String toLowerCase(): Returns a new string after converting all the uppercase letters to lowercase …

toLowerCase() String Example Read More »

concat() String Example

java.lang.String class comes with concat() String method to concatenate two strings. The signature is given as defined in String class. public String concat(String str): Returns a new string, the result of concatenation of two strings. Following example concat() String illustrates the usage concat() method. public class StringMethodDemo { public static void main(String args[]) { String …

concat() String Example Read More »

toUpperCase() String Example

java.lang.String class comes with toUpperCase() String method to convert all lowercase letters into uppercase in the string. After modification, a new string is returned with all the conversions. The signature toUpperCase() String is given as defined in Java API. public String toUpperCase(): Returns a new string after converting all the lowercase letters to uppercase letters …

toUpperCase() String Example Read More »

replaceFirst() String Example

After seeing replace() method in String, let us study another similar method replaceFirst() String. What Java API says about the method: String replaceFirst (String str, String replaceString): Replaces the first occurrence of str in the original string(calling string) with replaceString, The original string is not getting disturbed, but the returned string gets effected. See example. …

replaceFirst() String Example Read More »

toUpperCase(), toLowerCase() and replace() String

Here, we do some miscellaneous operations on strings like converting a string from lowercase to uppercase or vice versa, removing unwanted prefix and suffix whitespaces and replacing a few characters with replace() String. Supported methods from String class. String toLowerCase(): Returns a new string containing all lowercase characters. All the uppercase characters are converted into …

toUpperCase(), toLowerCase() and replace() String Read More »

replace() String Example

java.lang.String class comes with replace() String method to replace existing characters in a sting with new characters. The signature of replace() String as given in Java API. public String replace(char oldChar, char newChar): Returns a new string after replacing characters. All the occurrences of oldChar in the string are replaced by newChar. In the following …

replace() String Example Read More »

Java String Find matching characters indexOf(), lastIndexOf()

To Java String find matching, we use three methods – overloaded indexOf() and lastIndexOf() and charAt(). Index numbers are given by the JVM implicitly to the characters in the string; the first character is given 0, the second one as 1 and so on. These index numbers are helpful in programming in searching operations. Following …

Java String Find matching characters indexOf(), lastIndexOf() Read More »

regionMatches() and intern() String Java

The String class is rich with abundant methods used in coding. One of the methods is overloaded regionMatches() used to find the existence of a few characters of one string in another. Supported methods from String class. boolean regionMatches(int positionFirstString, String secondString, int positionSecondString, int num): Returns a boolean value of true if the region …

regionMatches() and intern() String Java Read More »