Java String Split split(final String s)

Here you can find the source of split(final String s)

Description

This is not correct.

License

Open Source License

Parameter

Parameter Description
s to split

Return

fields

Declaration

static List<String> split(final String s) 

Method Source Code

//package com.java2s;
/*/*w  w  w  . j av a2 s. c o m*/
#    Copyright (c) 2007-2013 Cyrus Daboo. All rights reserved.
#
#    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.
*/

import java.util.ArrayList;

import java.util.List;

public class Main {
    /** This is not correct. For example the # character is a comment
     * OUTSIDE of quotes. We don't deal with that nor a field that
     * ends with #.
     *
     * @param s to split
     * @return fields
     */
    static List<String> split(final String s) {
        final List<String> res = new ArrayList<>();

        int len1 = s.length();
        String s1 = s;
        while (true) {
            final String s2 = s1.replace("  ", " ");
            final int len2 = s2.length();
            s1 = s2;
            if (len2 == len1) {
                break;
            }

            len1 = len2;
        }

        for (final String split : s1.split(" ")) {
            if (split.length() > 0) {
                if (split.startsWith("#")) {
                    break;
                }
                res.add(split);
            }
        }

        return res;
    }
}

Related

  1. split(byte[] input)
  2. split(final byte[] array, final int chunkSize)
  3. split(final int limit, String text)
  4. split(final String s)
  5. split(final String s)
  6. split(final String str)
  7. split(final String str)
  8. split(final String string)
  9. split(final String string)