Java String to Array stringToArray(String inputVal, String delimiter)

Here you can find the source of stringToArray(String inputVal, String delimiter)

Description

string To Array

License

Open Source License

Declaration

public static ArrayList<String> stringToArray(String inputVal, String delimiter) 

Method Source Code

//package com.java2s;

import java.util.ArrayList;

public class Main {
    public static ArrayList<String> stringToArray(String inputVal, String delimiter) {
        if (inputVal == null || inputVal.length() <= delimiter.length()) {
            return null;
        }/*from ww  w  .  j a v  a 2s  .  c  o m*/

        if (inputVal.indexOf(delimiter) == 0) {
            inputVal = inputVal.substring(delimiter.length());
        }
        if (inputVal.indexOf(delimiter) == inputVal.length() - delimiter.length()) {
            inputVal = inputVal.substring(0, inputVal.length() - delimiter.length());
        }
        String[] vals = inputVal.split(delimiter);
        ArrayList<String> returnList = new ArrayList<String>();
        try {
            for (int i = 0; i < vals.length; i++) {
                returnList.add(vals[i].trim());
            }
        } catch (Exception ex) {
            returnList = null;
        }
        return returnList;
    }
}

Related

  1. stringToArray(final String data, final String delim)
  2. stringToArray(String charc, String commas)
  3. stringToArray(String s)
  4. stringToArray(String str, String separator)
  5. stringToByteArray(String text, int length)