String str = "Hello world!"; String newStr = StringUtils.replaceChars(str, 'o', '0'); System.out.println(newStr); // Prints "Hell0 w0rld!"
String str = "Java is great!"; String newStr = StringUtils.replaceChars(str, "aeiou", "AEIOU"); System.out.println(newStr); // Prints "JAvA Is grEAt!"Here, replaceChars replaces all occurrences of vowels in the String with their uppercase counterparts, resulting in "JAvA Is grEAt!". This method belongs to the Apache Commons Lang package library.