Java List和Array之间的转换

java

import java.util.Arrays;

import java.util.List;

class Test {

//Object数组向List的转换

public static List<String> testArray2List(String[] args) {

return Arrays.asList(args);

}

public static String[] testList2Array(List<String> args){

List<String> list2 = Arrays.asList("aaa", "bbb", "ccc");

String[] array = list2.toArray(new String[list2.size()]);

System.out.println(array);

for (String s : array){

System.out.println(s);

}

return args.toArray(new String[args.size()]);

}

public static void main(String[] args) {

List<String> list1 = Test.testArray2List(new String[]{"aaa", "bbb", "ccc"});

System.out.println(list1);

}

}

输出

[aaa, bbb, ccc]

以上是 Java List和Array之间的转换 的全部内容, 来源链接: utcz.com/z/390674.html

回到顶部