字符串转list ["777777777","777777778","4130235","4130236"] java
时间: 2023-12-11 12:33:56 浏览: 137
以下是将逗号分割的字符串转为List的Java代码示例:
```java
public static <T> List<String> idsStrToList(String idsStr) {
return Arrays.asList(idsStr.split(","));
}
```
使用示例:
```java
String str = "777777777,777777778,4130235,4130236";
List<String> list = idsStrToList(str);
System.out.println(list); // 输出:[777777777, 777777778, 4130235, 4130236]
```
以下是将任意符号分割的字符串转为List的Java代码示例:
```java
public static <T> List<String> idsStrToListSeparator(String idsStr, String separator) {
return Arrays.asList(idsStr.split(separator));
}
```
使用示例:
```java
String str = "777777777|777777778|4130235|4130236";
List<String> list = idsStrToListSeparator(str, "\\|");
System.out.println(list); // 输出:[777777777, 777777778, 4130235, 4130236]
```
阅读全文