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 138 views
1 answer 148 views
1 answer 130 views
2 answers 221 views
1 answer 123 views
1 answer 164 views
...