fork download
  1. class Test{
  2. public static void main(String[] args){
  3. String str="John is working in London";
  4. String[] arr=str.replaceAll("([\" \"])\\1+"," ").split(" ");
  5. for(String i:arr){
  6. System.out.println(i.trim());
  7. }
  8. }
  9.  
  10.  
  11. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
John
is
working
in
London