java 英文逗号隔开字符串转数组
时间: 2023-08-14 16:11:29 浏览: 107
Java StringUtils字符串分割转数组的实现
To convert a comma-separated string into an array in Java, you can use the `split()` method from the `String` class. Here's an example:
```java
String str = "apple,banana,orange";
String[] arr = str.split(",");
// Printing the elements of the array
for (String item : arr) {
System.out.println(item);
}
```
Output:
```
apple
banana
orange
```
In this example, the `split(",")` method is used to split the string `str` at each occurrence of a comma (`,`) and returns an array of substrings.
阅读全文