Java how to saperate string to array

Java how to saperate string to array

To split a string into an array in Java, you can use the split method of the String class. The split method takes a regular expression as an argument and returns an array of substrings that are split by the regular expression.

For example, consider the following string:

refe‮ual:ot r‬tturi.com
String str = "apple,banana,cherry,date";

To split this string into an array on the comma delimiter, you can use the following code:

String[] arr = str.split(",");

This will create an array arr with the following elements:

arr[0] = "apple"
arr[1] = "banana"
arr[2] = "cherry"
arr[3] = "date"

You can also use the split method with a different regular expression to split the string by a different delimiter. For example, to split the string on the | character, you can use the following code:

String[] arr = str.split("|");
Created Time:2017-11-03 23:27:11  Author:lautturi