How to split a string into an array in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String str = "java, c, c++, rust, python, php";
        
        String[] arr = str.split(", ");

        for (String s: arr) {
            System.out.println(s);
        }
    }
}




/*
run:

java
c
c++
rust
python
php

*/

 



answered Mar 13, 2023 by avibootz

Related questions

...