Java String Split by Regex splitNoEmpty(String sStr, String regex)

Here you can find the source of splitNoEmpty(String sStr, String regex)

Description

split No Empty

License

Apache License

Declaration

private static ArrayList<String> splitNoEmpty(String sStr, String regex) 

Method Source Code

//package com.java2s;
/*//from   w  w  w .  j  a v  a2  s.  c om
 * Copyright 2013 SciFY NPO <info@scify.org>.
 *
 * This product is part of the NewSum Free Software.
 * For more information about NewSum visit
 * 
 *    http://www.scify.gr/site/en/our-projects/completed-projects/newsum-menu-en
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * If this code or its output is used, extended, re-engineered, integrated, 
 * or embedded to any extent in another software or hardware, there MUST be 
 * an explicit attribution to this work in the resulting source code, 
 * the packaging (where such packaging exists), or user interface 
 * (where such an interface exists). 
 * The attribution must be of the form "Powered by NewSum, SciFY"
 */

import java.util.ArrayList;

public class Main {
    private static ArrayList<String> splitNoEmpty(String sStr, String regex) {
        String[] aIn = sStr.split(regex);
        ArrayList<String> lRes = new ArrayList<String>();
        if (aIn.length == 0) {
            lRes.add("");
            return lRes;
        }
        for (int i = 0; i < aIn.length; i++) {
            if (!aIn[i].isEmpty() && !aIn[i].matches("\\s+") && aIn[i].length() > 1) {
                lRes.add((String) aIn[i]);
            }
        }
        return lRes;
    }
}

Related

  1. split(String str, String regex)
  2. split(String string, String pattern)
  3. split(String text, String pattern)
  4. splitAndTrim(String s, String regex)
  5. splitList(String list, String splitRegex)
  6. splitString(String str, List list, String regex)
  7. splitStringToList(String input, String regex)
  8. splitTerms(String text, String pattern)
  9. splitToList(String s, String regex)