split a string by comma sign in java
Code snippet on how to split a string by comma sign in java
String str = "Hello, World!";
String[] stringArray = str.split(",");
This code snippet uses the split() method in Java to break apart a string based on a given delimiter (in this case, a comma sign). The first line creates a string object named ‘str’ with the value “Hello, World!”. The second line calls the split() method on ‘str’, specifies the delimiter (a comma sign) as an argument, and assigns the result to a string array called ‘stringArray’. The split() method will break the string into an array of two strings, “Hello” and “ World!”.