optimize for empty string case

This commit is contained in:
Shay Banon 2011-07-26 16:37:04 +03:00
parent 6e8c7c41fe
commit 15b9e00888
1 changed files with 3 additions and 0 deletions

View File

@ -1007,6 +1007,9 @@ public class Strings {
} }
public static String[] splitStringToArray(final String s, final char c) { public static String[] splitStringToArray(final String s, final char c) {
if (s.length() == 0) {
return Strings.EMPTY_ARRAY;
}
final char[] chars = s.toCharArray(); final char[] chars = s.toCharArray();
int count = 1; int count = 1;
for (final char x : chars) { for (final char x : chars) {