Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Java by (920 points)

I have a string like this:

mysz = "name=john age=13 year=2001";

I want to remove the whitespaces in the string. I tried trim() but this removes only whitespaces before and after the whole string. I also tried replaceAll("\\W", "") but then the = also gets removed.

How can I achieve a string with:

mysz2 = "name=johnage=13year=2001"

1 Answer

0 votes
by (13.2k points)

To remove all the whitespaces in between a string in java you can use java. replaceAll() method.It’s syntax is as shown below

String.replaceAll(String regex, String replacement) 

Regex is the string to be replaced and replacement is the string to be replaced with.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...