Java String Split by Delimiter split(String s, String delim)

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

Description

split

License

Open Source License

Declaration

public static List<String> split(String s, String delim) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {

    public static List<String> split(String s, String delim) {
        List<String> list = new ArrayList<String>();
        s = trim(s);//w w  w. j a  v  a 2  s.  c o m
        if (s == null) {
            return list;
        }
        String[] rs = s.split(delim);
        for (String str : rs)
            if (str.trim().length() > 0) {
                list.add(str);
            }
        return list;
    }

    public static String trim(String s) {
        if (s == null) {
            return "";
        }
        return s.trim();
    }

    public static String[] add(String[] array, String... strs) {
        Set<String> list = new HashSet<String>(Arrays.asList(array));
        Collections.addAll(list, strs);
        return list.toArray(new String[list.size()]);
    }
}

Related

  1. split(String s, char delim)
  2. split(String s, char delimiter)
  3. split(String s, char delimiter)
  4. split(String s, char delimiter)
  5. split(String s, char delimiter)
  6. split(String s, String delim)
  7. split(String s, String delim)
  8. split(String s, String delimiter)
  9. split(String s, String delimiter)