How to split a string into string array in Java

1 Answer

0 votes
public class JavaApplication {
    public static void main(String args[]) {
         try {
 
            String str = "java,c,c++,php,c#,c-3po";
 
            String arr[] = str.split(",");
 
            for (String s : arr) {
                System.out.println(s);
            }
 
        } catch (Exception e) {
            System.out.println(e.toString());
        }
    }
}
 
 
 
 
/*
run:
 
java
c
c++
php
c#
c-3po
 
*/

 



answered Jun 25, 2019 by avibootz
edited May 2, 2024 by avibootz

Related questions

1 answer 127 views
1 answer 155 views
1 answer 233 views
1 answer 362 views
1 answer 192 views
...