How to split a string into a collection in Java

1 Answer

0 votes
import java.util.Arrays;
import java.util.Collection;

public class MyClass {
    public static void main(String args[]) {
        String str = "java, c, c++, rust, python, php";
        
        Collection<String> co = Arrays.asList(str.split(", "));

        System.out.println(co);
    }
}




/*
run:

[java, c, c++, rust, python, php]

*/

 



answered Mar 13, 2023 by avibootz

Related questions

...