Here you can find the source of split(final String s)
Parameter | Description |
---|---|
s | to split |
static List<String> split(final String s)
//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; } }