Here you can find the source of split(final String text, final char separator)
text
around separator
.
Parameter | Description |
---|---|
text | a parameter |
separator | a parameter |
public static final List<String> split(final String text, final char separator)
//package com.java2s; import java.util.ArrayList; import java.util.List; public class Main { /**//from w w w .j a v a 2 s .c o m * Splits <code>text</code> around <code>separator</code>. * * @param text * @param separator * @return */ public static final List<String> split(final String text, final char separator) { final List<String> strings = new ArrayList<>(); final int length = text.length(); final char[] characters = new char[length + 1]; characters[length] = separator; text.getChars(0, length, characters, 0); int start = 0, end = 0; for (final char letter : characters) { if (letter == separator) { strings.add(new String(characters, start, end - start)); start = ++end; } else { ++end; } } return strings; } public static final int getChars(final String source, final int sourceBegin, final int sourceEnd, final char destination[], final int destinationBegin) { int d = destinationBegin; for (int s = sourceBegin; s < sourceEnd; ++s, ++d) { destination[d] = source.charAt(s); } return d; } }