Java Reference
In-Depth Information
actually apply the pattern and so the whole string is returned
as the zeroth element. A limit of two applies the pattern once,
breaking the string into two substrings. A limit of three gives
us three substrings. A limit of four gives us four substrings,
with the fourth being the empty string due to the original
string ending with the pattern we were splitting on. Any lim-
it greater than four will return the same results as a limit of
four.
In all the above, if the regular expression syntax is incorrect a
Pat-
ternSyntaxException
is thrown.
These are all convenience methods that avoid the need to work with
Pattern
and
Matcher
objects directly, but they require that the regular
expression be compiled each time. If you just want to know if a given
string matches a given regular expression, the
matches
method returns a
boolean
to tell you.
Case issues are
locale sensitive
that is, they vary from place to place
and from culture to culture. The platform allows users to specify a loc-
ale, which includes language and character case issues. Locales are rep-
resented by
Locale
objects, which you'll learn about in more detail in
default locale, or you can pass a specific locale as an argument:
public String
toLowerCase()
Returns a
String
with each character converted to its lower-
case equivalent if it has one according to the default locale.
public String
toUpperCase()
Returns a
String
with each character converted to its upper-
case equivalent if it has one according to the default locale.
public String
toLowerCase(Locale loc)