How to convert string to array of words in Java

1 Answer

0 votes
public class Main {
    public static void main(String[] args) {
        String str = "C++ C Java Python PHP Rust";
        
        // Split the string into an array of words
        String[] words = str.split(" ");
        
        for (String word : words) {
            System.out.println(word);
        }
    }
}



/*
run:

C++
C
Java
Python
PHP
Rust

*/

 



answered Nov 24, 2024 by avibootz
...