How to print String array without empty strings in Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {

    public static void main(String[] args) {

        try {

            String str = "java,c,@c++:,php!,c#,$c-3po$r2-d2$$$";

            String arr[] = str.split("[,:@!$]");

            for (String s : arr) {
                if (!"".equals(s)) {
                    System.out.println(s);
                }
            }

        } catch (Exception e) {
            System.out.println(e.toString());
        }
    }
}

/*
               
run:
  
java
c
c++
php
c#
c-3po
r2-d2
      
 */

 



answered Dec 15, 2016 by avibootz

Related questions

1 answer 118 views
2 answers 320 views
1 answer 206 views
1 answer 96 views
1 answer 163 views
1 answer 104 views
104 views asked Oct 8, 2021 by avibootz
...