How to convert string to string array using regex pattern in Java

1 Answer

0 votes
import java.util.regex.Pattern;

public class MyClass {
    public static void main(String args[]) {
        String s = "java c++ c c# python";

        Pattern pattern = Pattern.compile(" ");
        String[] arr = pattern.split(s);

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




/*
run:

java
c++
c
c#
python

*/

 



answered Dec 15, 2020 by avibootz
...