在 Java 中按照逗号 (,) 分割字符串
假设以下字符串为我们的字符串。
String str = " This is demo text, and demo line!";
要使用逗号分隔字符串,请使用 Java 中的 split() 方法。
str.split("[,]", 0);以下是一个完整的示例。
示例
public class Demo { public static void main(String[] args) { String str = "This is demo text, and demo line!"; String[] res = str.split("[,]", 0); for(String myStr: res) { System.out.println(myStr); } } }
输出
This is demo text and demo line!
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP