public class StringUtil
extends java.lang.Object
StringUtil
is a utility class with static methods
for counting and returning delimited fields in a string.Modifier and Type | Method and Description |
---|---|
static int |
countFields(java.lang.String s)
Returns the number of white-space delimited fields in the specified
string.
|
static int |
countFields(java.lang.String s,
char delimiter)
Returns the number of delimited fields in the specified
string.
|
static int |
countFields(java.lang.String s,
char delimiter,
int max)
Returns
Math.min(countFields(s, delimiter), max) . |
static java.lang.String[] |
getFields(java.lang.String s)
Returns an array obtained by trimming white-space from the
beginning and end of the specified string, and splitting the resulting
string around white space.
|
static java.lang.String[] |
getFields(java.lang.String s,
char delimiter)
Returns an array obtained by splitting the specified string
around the specified delimiter.
|
static java.lang.String[] |
getFields(java.lang.String s,
char delimiter,
int limit)
Returns an array obtained by splitting the specified string
around the first
(limit - 1) occurrences of the specified
delimiter. |
static java.lang.String[] |
getFields(java.lang.String s,
int limit)
Returns an array obtained by trimming white-space from the
beginning and end of the specified string, and splitting the resulting
string around the first
(limit-1) white-space delimiters. |
public static int countFields(java.lang.String s, char delimiter)
s
- a stringdelimiter
- a delimiter characterjava.lang.NullPointerException
- if s == null
public static int countFields(java.lang.String s, char delimiter, int max)
Math.min(countFields(s, delimiter), max)
.s
- a string with 0 or more delimiter
charactersdelimiter
- the delimiter charactermax
- the maximum value that can be returnedMath.min(countFields(s, delimiter), max)
java.lang.NullPointerException
- if s == null
public static java.lang.String[] getFields(java.lang.String s, char delimiter)
s
- a stringdelimiter
- a delimiter characterjava.lang.NullPointerException
- if s == null
public static java.lang.String[] getFields(java.lang.String s, char delimiter, int limit)
(limit - 1)
occurrences of the specified
delimiter. If the string contains fewer than (limit - 1)
delimiter characters, the returned value will equal
StringUtil.getFields(s, delimiter)
s
- a stringdelimiter
- a delimiter characterlimit
- the maximum length of the returned arrayjava.lang.NullPointerException
- if s == null
java.lang.IllegalArgumentException
- if limit < 2
public static int countFields(java.lang.String s)
s
- a stringjava.lang.NullPointerException
- if s == null
public static java.lang.String[] getFields(java.lang.String s)
s
- a stringjava.lang.NullPointerException
- if s == null
public static java.lang.String[] getFields(java.lang.String s, int limit)
Returns an array obtained by trimming white-space from the
beginning and end of the specified string, and splitting the resulting
string around the first (limit-1)
white-space delimiters.
A white-space delimiter is any maximal substring of unicode characters
less than or equal to '\u0020'. If the trimemed string contains
fewer than (limit - 1)
white space delimiters, the returned value
will equal StringUtil.getFields(s)
. The substrings in the
returned array are in the order in which they occur in this string.
If there are no white-space delimiters in the specified string, the
method returns an array of length one whose single element is the
trimmed string. If the specified string contains only white-space,
a string array of length 0 is returned.
s
- a stringlimit
- the maximum length of the returned arrayjava.lang.NullPointerException
- if s == null
java.lang.IllegalArgumentException
- if limit < 2