String轉List:
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
class Father{
void methodFather(){
System.out.println("Father");
}
}
class Son extends Father {
void methodSon(){
System.out.println("Son");
}
}
public class Test {
public static void main(String[] args){
String str = "1,2,3,4,5,6,7,8";
String[] strArr= str.split(",");
List<String> list = Arrays.asList(strArr);
List<String> list1 = new ArrayList<>();
Collections.addAll(list1, strArr);
}
}
複製代碼
List轉String:
import com.sun.deploy.util.StringUtils;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
class Father{
void methodFather(){
System.out.println("Father");
}
}
class Son extends Father {
void methodSon(){
System.out.println("Son");
}
}
public class Test {
public static void main(String[] args){
List<String> list = new ArrayList<>();
list.add("a");
list.add("b");
list.add("c");
String[] strArr = list.toArray(new String[list.size()]);
String str1 = String.join(",", strArr);
String str = StringUtils.join(list, ",");
}
}
複製代碼