In the earlier article, I have shown you how to split String by regular expression and now, you will learn how to split String by comma. Since CSV is a popular format of exporting data, you often need to split a comma separated String to create an array of individual Strings. Similar to the earlier example, you can use the split() method to accomplish this task. Just pass a "," instead of "\\s+" the regular expression to remove whitespaces, as the regular expression. The split method will return an array of String, which you can further convert to a list of String. If your String contains a leading or trailing white space, make sure you trim the String before calling the split() method. Also, remember that this method will throw PatternSyntaxException if the regular expression's syntax is invalid. Lat but not the least this version of the split method is only available from Java 1.4 onwards.
Read more »