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…

Java-IgnoreCase

IgnoreCase A minor variant of the equals( ) method, namely the equalsIgnoreCase( ) method is also available. This method ignores the case of each character in the strings during the comparison. For example, in the following program, the case of each character is ignored by the equalsIgnoreCase( ) method, this method will return the value … Read more…

Java-Case Conversions

Case Conversions As the Java language is case sensitive, it differentiates uppercase letters from lowercase letters. The String class provides two methods, namely toLowerCase( ) and toUpperCase( ) to facilitate case conversions. While the toLowerCase( ) method converts all the letters of the given string to lower case, the toUpperCase( ) method does just the … Read more…

Java-String Comparison

String Comparison We use the == operator for comparing the values of two variables or expressions of any data type, such as int, float, double, char and boolean. But we have to use the equals( ) method of the String class for comparing two strings. This method is used to find the contents are same, … Read more…