Skip to content

Commit 2818838

Browse files
committed
Update StringUtils.java
1 parent 49094a2 commit 2818838

1 file changed

Lines changed: 3 additions & 22 deletions

File tree

microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import static java.lang.Character.isWhitespace;
3333
import static java.lang.Character.toLowerCase;
3434
import static java.lang.Character.toUpperCase;
35+
import static java.lang.String.valueOf;
3536

3637
/**
3738
* The utilities class for {@link String}
@@ -132,27 +133,7 @@ public static boolean isNotBlank(String value) {
132133
*/
133134
@Nonnull
134135
public static String[] split(@Nullable String value, char delimiter) {
135-
int length = length(value);
136-
if (length < 1) {
137-
return EMPTY_STRING_ARRAY;
138-
}
139-
140-
List<String> result = new ArrayList<>();
141-
142-
int startIndex = 0;
143-
int endIndex;
144-
145-
while ((endIndex = value.indexOf(delimiter, startIndex)) > -1) {
146-
String part = value.substring(startIndex, endIndex);
147-
result.add(part);
148-
startIndex = endIndex + 1;
149-
}
150-
if (startIndex <= length) {
151-
// Add rest of String, but not in case of empty input.
152-
result.add(value.substring(startIndex));
153-
}
154-
155-
return toStringArray(result);
136+
return split(value, valueOf(delimiter));
156137
}
157138

158139
/**
@@ -852,7 +833,7 @@ public static String uncapitalize(String str) {
852833
*/
853834
@Nonnull
854835
public static String[] toStringArray(@Nullable Collection<String> collection) {
855-
return (!isEmpty(collection) ? collection.toArray(EMPTY_STRING_ARRAY) : EMPTY_STRING_ARRAY);
836+
return isEmpty(collection) ? EMPTY_STRING_ARRAY : collection.toArray(EMPTY_STRING_ARRAY);
856837
}
857838

858839
static String changeFirstCharacter(String str, boolean capitalize) {

0 commit comments

Comments
 (0)