String to ArrayList
first cut the string according to a certain character, convert it to a string array,
and then use the asList method of Arrays to convert the array to List
public class test1 {
public static void main(String[] args) {
//string 转 ArrayList
String str1 = "a,b,c";
ArrayList<String> list =
new ArrayList<String>(Arrays.asList(str1.split(",")));
System.out.println(list);
}
}
ArrayList to string
public class test1 {
public static void main(String[] args) {
//ArrayList 转 string
ArrayList<String> list = new ArrayList<String>();
list.add("a");
list.add("b");
list.add("c");
System.out.println(list);//[a, b, c]
String list_str = StringUtils.join(list,",");
System.out.println(list_str);//a,b,c
}
}
If it is an int to an arraylist, convert the int to a string first
For the public account: Micro Program School