public class MainClass
{
public static void main( String args[] )
{
String secondString = "1, 2, 3, 4, 5, 6, 7, 8";
String output = "String split at commas: [";
String[] results = secondString.split( ",\\s*" ); // split on commas
for ( String string : results )
output += "\"" + string + "\", ";
output = output.substring( 0, output.length() - 2 ) + "]";
System.out.println( output );
}
}
String split at commas: ["1", "2", "3", "4", "5", "6", "7", "8"]