How to split the first two words from a string in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String s = "java,c++,php,python,c#";
        String[] arr = s.split(",", 3);
        
        for (String val : arr) {
            System.out.println(val);
        }
    }
}



/*
run:

java
c++
php,python,c#

*/

 



answered Jul 31, 2020 by avibootz
...