Java String Split split(String str, int ch)

Here you can find the source of split(String str, int ch)

Description

split

License

Open Source License

Declaration

public static List<String> split(String str, int ch) 

Method Source Code

//package com.java2s;

import java.util.*;

public class Main {
    public static List<String> split(String str, int ch) {
        int begin = 0;
        for (; begin < str.length(); begin++) {
            if (str.charAt(begin) != ch) {
                break;
            }//from   www.j a va  2s .  com
        }
        if (begin > 0) {
            str = str.substring(begin);
            begin = 0;
        }

        int idx = str.indexOf(ch);
        if (idx == -1) {
            return Arrays.asList(str.trim());
        } else {
            ArrayList<String> strs = new ArrayList<String>(2);
            while (idx > -1) {
                String s = str.substring(begin, idx).trim();
                if (s.length() > 0) {
                    strs.add(s);
                }
                begin = idx + 1;
                idx = str.indexOf(ch, begin);
            }
            String s = str.substring(begin).trim();
            if (s.length() > 0) {
                strs.add(s);
            }
            return strs;
        }
    }
}

Related

  1. split(String str)
  2. split(String str)
  3. split(String str)
  4. split(String str)
  5. split(String str)
  6. split(String str, String id)
  7. split(String str, String splitStr)
  8. split(String str, String splitter)
  9. split(String str, String token)