Android String Split split(String source, String separator, int arraylength)

Here you can find the source of split(String source, String separator, int arraylength)

Description

split

Declaration

public static String[] split(String source, String separator,
        int arraylength) throws NullPointerException 

Method Source Code

//package com.java2s;

public class Main {

    public static String[] split(String source, String separator)
            throws NullPointerException {
        String[] returnVal = null;
        int cnt = 1;

        int index = source.indexOf(separator);
        int index0 = 0;
        while (index >= 0) {
            cnt++;/*w w w.ja  va 2s  . c om*/
            index = source.indexOf(separator, index + 1);
        }
        returnVal = new String[cnt];
        cnt = 0;
        index = source.indexOf(separator);
        while (index >= 0) {
            returnVal[cnt] = source.substring(index0, index);
            index0 = index + 1;
            index = source.indexOf(separator, index + 1);
            cnt++;
        }
        returnVal[cnt] = source.substring(index0);

        return returnVal;
    }

    public static String[] split(String source, String separator,
            int arraylength) throws NullPointerException {
        String[] returnVal = new String[arraylength];
        int cnt = 0;
        int index0 = 0;
        int index = source.indexOf(separator);
        while (index >= 0 && cnt < (arraylength - 1)) {
            returnVal[cnt] = source.substring(index0, index);
            index0 = index + 1;
            index = source.indexOf(separator, index + 1);
            cnt++;
        }
        returnVal[cnt] = source.substring(index0);
        if (cnt < (arraylength - 1)) {
            for (int i = cnt + 1; i < arraylength; i++) {
                returnVal[i] = "";
            }
        }

        return returnVal;
    }

    public static int indexOf(String str, String searchStr) {
        if (str == null || searchStr == null) {
            return -1;
        }
        return str.indexOf(searchStr);
    }
}

Related

  1. getLine(String text, int line)
  2. stringToLongArray(String src, String separator)
  3. strToArray(String string)
  4. strToArray(String string, String delim)
  5. getStringArray(String str)
  6. split(String str, String delims, boolean trimTokens)
  7. stringToListStr(String input)
  8. splitStringOnWhitespace(String stringToSplit)
  9. stringToListByLine(final String fileContent)