Java String Split split(final String s)

Here you can find the source of split(final String s)

Description

split

License

Apache License

Declaration

public static String[] split(final String s) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static String[] split(final String s) {
        if (s == null) {
            return null;
        }//ww w . j a  v  a 2  s  . c  o m
        final List<String> l = new ArrayList<String>();
        for (final String i : s.split(",")) {
            if (i == null) {
                continue;
            }
            final String sp = i.trim();
            if (sp.length() == 0) {
                continue;
            }
            l.add(sp);
        }
        return l.toArray(new String[0]);
    }

    public static String[] split(final String s, final String sep) {
        if (s == null) {
            return null;
        }
        final List<String> l = new ArrayList<String>();
        for (final String i : s.split(sep)) {
            if (i == null) {
                continue;
            }
            final String sp = i.trim();
            if (sp.length() == 0) {
                continue;
            }
            l.add(sp);
        }
        return l.toArray(new String[0]);
    }
}

Related

  1. split(byte[] data)
  2. split(byte[] input)
  3. split(byte[] input)
  4. split(final byte[] array, final int chunkSize)
  5. split(final int limit, String text)
  6. split(final String s)
  7. split(final String s)
  8. split(final String str)
  9. split(final String str)