String字符串转集合(简单高效)
public static void main(String[] args) {
String str = "111,222,333,444";
List list=Arrays.asList(str.split(","));
}
String字符串(集合里嵌套集合情况下)转集合(fastjson)
List<T> list=JSONArray.parseArray(“”,T.class);
public static void main(String[] args) {
String ids = "[[111,222,333,444],[111,222,333,444]]";
List<String> list=JSONArray.parseArray(ids,String.class);
for (int i = 0; i < list.size(); i++) {
List<String> list2=JSONArray.parseArray(list.get(i),String.class);
for (int j = 0; j < list2.size(); j++) {
System.out.println(list2.get(j));
}
}
}
String字符串(集合里是map情况下)转集合(gson)
public static void main(String[] args) {
String str = "[{111:222,333:444},{111:222,333:444}]";
Gson gson = new Gson();
List<Map<String,String>> list = gson.fromJson(str, new TypeToken<List<Map<String, String>>>() {}.getType());
}