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 287 views
1 answer 276 views
3 answers 756 views
1 answer 235 views
2 answers 393 views
1 answer 266 views
...