How to remove all spaces from a string in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String str = "Remove all spaces from string in Java";

	    str = str.replaceAll("\\s+","");

	    System.out.println(str);
    }
}





/*
run:
 
RemoveallspacesfromstringinJava
 
*/

 



answered Nov 10, 2022 by avibootz

Related questions

1 answer 195 views
195 views asked Mar 30, 2021 by avibootz
1 answer 288 views
1 answer 265 views
1 answer 299 views
1 answer 282 views
...