How to extract all words from a string in Java

1 Answer

0 votes
import java.util.Arrays;

public class MyClass {
    public static void main(String args[]) {
        String s = "java python javascript c c++ php";
          
        String[] words = s.split(" ");
  
        for (String str : words) {
            System.out.println(str);
        }
    }
}
 
 
 
 
/*
run:
 
java
python
javascript
c
c++
php
 
*/

 



answered Feb 9, 2022 by avibootz

Related questions

...