Java String Split by Separator splitField(String fieldWithSeparator, String separator)

Here you can find the source of splitField(String fieldWithSeparator, String separator)

Description

Splits a multiple-value composed field into a list of String values

License

Open Source License

Parameter

Parameter Description
fieldWithSeparator a parameter
separator a parameter

Declaration

public static List<String> splitField(String fieldWithSeparator, String separator) 

Method Source Code


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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    /**//from www  .ja va 2s .  c o m
     * Splits a multiple-value composed field into a list of String values
     * 
     * @param fieldWithSeparator
     * @param separator
     * @return
     */
    public static List<String> splitField(String fieldWithSeparator, String separator) {
        List<String> fieldsList = new ArrayList<String>();
        if (fieldWithSeparator == null) {
            return fieldsList;
        }

        String[] fields = fieldWithSeparator.split(separator);
        fieldsList = new ArrayList<String>(Arrays.asList(fields));

        return fieldsList;
    }
}

Related

  1. splitAll(String str, char separatorChar)
  2. splitAndTrim(String tags, String separator)
  3. splitBySeparator(String path, String separator)
  4. splitByStringSeparator(String theString, String separatorString)
  5. splitDoubles(String str, String fieldSeparator)
  6. splitInts(String string, String separator)
  7. splitList(String source, char separator)
  8. splitListBySeparator(String text, String separator)
  9. splitNotRegex(String str, String separatorChars)