How to split string into array of words in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String name = "James John William";
  
        String[] arr = name.split(" ");
  
        for (String s : arr) {
            System.out.println(s);
        }
    }
}



/*
run:
     
James
John
William
     
*/

 



answered Nov 24, 2021 by avibootz
...