String replaceAll() example - How to replace all characters and substring from String

You can replace all occurrence of a single character, or a substring of a given String in Java using the replaceAll() method of java.lang.String class. This method also allows you to specify the target substring using the regular expression, which means you can use this to remove all white space from String. The replaceAll() function is very useful, versatile and powerful method and as a Java developer, you must know about it. Even though Java provides separate methods for replacing characters and replacing substring, you can do all that just by using this single method. The replaceAll() method replaces each substring of this string (the String on which it is called) that matches the given regular expression with the given replacement. It internally uses classes like Pattern and Matcher from java.util.regex package for searching and replacing matching characters or substring.
Read more �

Posting Komentar

0 Komentar