Java 1.5 added a replace() method that could be used to replace all occurrences of a string wiuth another string
s = s.replace(" ", "");
Prior to 1.5 you can use a regular expression with the replaceAll() method to achieve that.
s = s.replaceAll(" ", ""); // Or to replace all whitespace s = s.replaceAll("\\s", "");
Let us know if you need a different solution.
Leave a Reply
You must be logged in to post a comment.