Java String Split by Space splitSpaces(String input)

Here you can find the source of splitSpaces(String input)

Description

Method to split a string using spaces ("/\\s+/" regex).

License

Open Source License

Parameter

Parameter Description
input The input string

Return

A java.util.List<String> with tokens != ""

Declaration

public static List<String> splitSpaces(String input) 

Method Source Code


//package com.java2s;
/*/*from  w  ww.ja  v a2s  .c o m*/
LWKT - A light WKT parser written in Java
    
Copyright (C) 2011 Francesco Cutruzzula' (www.cutruzzula.it)
    
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
    
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.
    
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

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

public class Main {
    /** Method to split a string using spaces (&quot;/\\s+/&quot; regex).
     * @param input The input string
     * @return A java.util.List&lt;String&gt; with tokens != ""
     */
    public static List<String> splitSpaces(String input) {
        List<String> results = new ArrayList<String>();
        String parts[] = input.split("\\s+");

        for (int i = 0; i < parts.length; i++) {

            if (parts[i].length() > 0) {
                results.add(parts[i]);
            }

        }

        return results;
    }
}

Related

  1. splitInWhiteSpaces(String string)
  2. splitNamespaceTitle(String fullTitle)
  3. splitOnSpace(final String string)
  4. splitOnSpace(String string)
  5. SplitOnWhitespace(String instrData)
  6. splitStringOnWhitespace(String text)
  7. splitWithoutWhitespace(String source, String separator)
  8. whitespaceSplit(final String input)