Let's say you have a comma delimited file or a phrase that you want to divide each element on all the commas. This example will show how to parse a string on a comma using java, guava and apache commons. A similar example shows how to parse comma delimited string in groovy.
Straight up Java
Using java's core String.split function we will pass a regular expression that will return an array of strings computed by splitting the original on a comma.
Creating a stream from a string then applying the java 8 function to the elements will produce an Arraylist of String arrays. Calling the
flatmap will replace or combine each array into a single stream by flattening it. Finally we will convert stream into arraylist.
Using guava's Splitter class we will parse a comma delimited string by passing a comma as a separator to the on method. Next we will call the splitToList function that will split the sequence into chunks and make them available via an ArrayList.
This snippet will split text into an array using a comma as a separator using apache commons StringUtils.split.