将一个数组转换为list集合时,使用List <数组类型>list = Arrays.asList(数组),当转换后,list不可改变大小。
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public static void main(String[] args){
String []str = {"aaa","bbb","ccc"};
List<String> dayList = new ArrayList<String>(Arrays.asList(str));
dayList.add("aaa");
System.out.println(dayList);
----------------------------------------------------------------
List <String> list = Arrays.asList(str);
list.add("aaa");//不能支持的操作,因为list是不可以变化的,此时不能添加
System.out.println(list);
}
-------------------------------------------------------------------------
运行结果:
[aaa, bbb, ccc, aaa]
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.AbstractList.add(AbstractList.java:131)
at java.util.AbstractList.add(AbstractList.java:91)
String[] values = ...;
Set<String> staff = new HashSet<String>(Arrays.asList(values));
List<String> dayList = new ArrayList<String>();
dayList.addAll( Arrays.asList(values));
String[] measureArray = {"BOOK_PV","BOOK_USERCNT","BOOK_DEEP_USERCNT","ORDER_USERCNT","ORDER_TOTAL_FEE","ORDER_DEMAND_FEE","ORDER_TICKET_FEE","ARPU",
"ORDER_RATIO","DEEP_USERCNT_RATIO"};//分析指标
List<String> measureNames = new ArrayList<String>(Arrays.asList(measureArray));