Java String Split by Separator splitAndTrim(String tags, String separator)

Here you can find the source of splitAndTrim(String tags, String separator)

Description

split And Trim

License

Apache License

Declaration

public static List<String> splitAndTrim(String tags, String separator) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<String> splitAndTrim(String tags, String separator) {
        List<String> result = new ArrayList<String>();
        if (tags != null && tags.length() > 0) {
            for (String piece : tags.split(separator)) {
                if (hasText(piece)) {
                    result.add(piece.trim());
                }/*w ww .ja v a 2s. co  m*/
            }
        }
        return result;
    }

    public static boolean hasText(String str) {
        return hasLength(str) && str.trim().length() > 0;
    }

    public static boolean hasLength(String str) {
        return str != null && str.length() > 0;
    }
}

Related

  1. split(String str, String separator, boolean preserveEmptyToken)
  2. split(String string, char separator)
  3. split(String strToSplit, String strSeparator, int iLimit)
  4. split(String text, String separators, String brackets)
  5. splitAll(String str, char separatorChar)
  6. splitBySeparator(String path, String separator)
  7. splitByStringSeparator(String theString, String separatorString)
  8. splitDoubles(String str, String fieldSeparator)
  9. splitField(String fieldWithSeparator, String separator)