一、数组转化为list:Arrays.aslist(arr);
public static void main(String[] args) { String[] arr={"apple","pear"}; List<String> list=Arrays.asList(arr); System.out.println(list.size()); //===>2 }
二、list转化为数组 list.toArray();
package com.cmc.util; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class listUtil { public static void main(String[] args) { List<String> list = new ArrayList<String>(); list.add("str1"); list.add("str2"); int size=list.size(); String[] arr2= list.toArray(new String[size]); //*** 设置数组的大小 for (int i = 0; i < arr2.length; i++) { System.out.println("==arr2==:"+arr2[i]); } } }