How to remove extra white spaces between words from a string with regular expression in Java

1 Answer

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

 



answered Jun 28, 2019 by avibootz

Related questions

1 answer 290 views
1 answer 282 views
3 answers 764 views
1 answer 240 views
2 answers 398 views
1 answer 271 views
...