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 199 views
199 views asked Mar 30, 2021 by avibootz
1 answer 290 views
1 answer 270 views
1 answer 304 views
1 answer 287 views
...