How to remove all whitespace from string in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String s = "   java     c   c++      python    ";
 
        s = s.replaceAll("\\s", "");
 
        System.out.println(s);
    }
}
 
 
 
 
/*
run:
 
javacc++python
 
*/

 



answered Jan 14, 2022 by avibootz
edited Jan 15, 2022 by avibootz

Related questions

1 answer 131 views
1 answer 158 views
1 answer 158 views
3 answers 311 views
2 answers 178 views
...