November 2005
Intermediate to advanced
304 pages
6h 14m
English
Developers sometimes need to split a String into substrings using a delimiter such as a comma, tab, or whitespace. As we discussed in the previous section, Java 1.4 added the Pattern class for performing text comparisons with regular expressions. In addition to pattern matching, a Pattern object can split a String into an array of substrings, using the regular expression as the delimiter. For example, a one-line comma-delimited list can be split into an array of Strings, using a comma as the pattern:
String data = "Australia,Fiji,New Zealand,Papua New Guinea"; Pattern comma = Pattern.compile(","); String[] ...Read now
Unlock full access