Java String Replace
replace()
"Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar"
System.out.println(" D ev Dum my ".replace(" ",""));
"DevDummy"
System.out.println(" D ev Dum my ".replace(" ",""));
"DevDummy"
replaceAll()
"Replaces each substring of this string that matches the given regular expression with the given replacement"
System.out.println(" D ev Dum my ".replaceAll(" ",""));
System.out.println(" D ev Dum my ".replaceAll("\\s+",""));
System.out.println(" D ev Dum my ".replaceAll("\\s+",""));
"DevDummy"
"DevDummy"
"DevDummy"
Note: "\\s+" is the regular expression similar to the empty space character.
Reference
https://docs.oracle.com/javase/7/docs/api/java/lang/String.html...
No comments:
Post a Comment