String str = "tim,kerry,timmy,camden"; String results = str.split(",");
The split() method on the String class accepts a regular expression as its only parameter, and will return an array of String objects split according to the rules of the passed-in regular expression. This makes parsing a comma-separated string an easy task. In this phrase, we simply pass a comma into the split() method, and we get back an array of strings containing the comma-separated data. So the results array in our phrase would contain the following content:
results = tim results = kerry results = timmy results = camden
Another useful class for taking apart strings is the StringTokenizer class. We will repeat the phrase using ...