Java-RegionMatches

RegionMatches The String class provides one more specialized method for comparison. It is regionMatches( ) method. This method enables us to compare a specific region inside a string with another specific region in another string. For example, in the following program, a substring of length ‘4’ starting from the position ‘3’ in the String object … Read more…

Java-Comparing Length

Comparing Length It should be carefully noted here equals( ), equalsIgnoreCase( ) methods enable us to check whether two strings are identical or not. However, in some situations, we may wish to test whether one string is greater than, equal to or less than another string. The compareTo( ) method of the String class is … Read more…

Java-Extracting Characters

Extracting Characters If we wish to extract more than one character at a time from a string, we have to use the getChars( ) method. For example, in the following program, the characters staring from the position ‘5’ and ending with the position ’16-1′ will be extracted and then stored in the character array ‘str1′ … Read more…

Java-Replacement (Another Example)

replaceAll The capability of replaceAll() makes the complex search of substrings possible within a string object. After a search, each matched substring is replaced with the given replacement. Program Program Source public class Javaapp { public static void main(String[] args){ String str1 = new String(“Java Pro Tutorials”); str1 = str1.replaceAll(“Pro”, “Programming”); String str2 = new … Read more…

Java-Replacement in a String

replace The replace( ) method of the String class enables us to replace every occurrence of one character with another character. replaceFirst The replaceFirst( ) method of the String class enables us to replace first occurrence of substring with another substring. replaceAll The capability of replaceAll( ) makes the complex search of substrings possible within a string … Read more…

Java-Extracting Character

Extracting Character The charAt( ) method provides the character at the specified index position. The starting value of the index in the case of a string is zero. For example, in the following program, the character at position 3 in the string “hajsof” is ‘s’. Thus, the str1.charAt(3) method will return the character ‘s’. Concat … Read more…