String str = "test test1 test2 test3"; String [] arr= str.split("\\s+");for(String ss : arr){ System.out.println(ss); }