string[] staffs = new string[]{"tom", "bob", "jane"}; list staffslist = arrays.aslist(staffs);
需要注意的是, arrays.aslist()
返回一个受指定数组决定的固定大小的列表。所以不能做 add
、 remove
等操作,否则会报错。
list staffslist = arrays.aslist(staffs); staffslist.add("mary"); // unsupportedoperationexception staffslist.remove(0); // unsupportedoperationexception
如果想再做增删操作呢?将数组中的元素一个一个添加到列表,这样列表的长度就不固定了,可以进行增删操作。
list staffslist = new arraylist<string>(); for(string temp: staffs){ staffslist.add(temp); } staffslist.add("mary"); // ok staffslist.remove(0); // ok
string[] staffs = new string[]{"tom", "bob", "jane"}; set<string> staffsset = new hashset<>(arrays.aslist(staffs)); staffsset.add("mary"); // ok staffsset.remove("tom"); // ok
string[] staffs = new string[]{"tom", "bob", "jane"}; list staffslist = arrays.aslist(staffs); object[] result = staffslist.toarray();
string[] staffs = new string[]{"tom", "bob", "jane"}; list staffslist = arrays.aslist(staffs); set result = new hashset(staffslist);
string[] staffs = new string[]{"tom", "bob", "jane"}; set<string> staffsset = new hashset<>(arrays.aslist(staffs)); object[] result = staffsset.toarray();
string[] staffs = new string[]{"tom", "bob", "jane"}; set<string> staffsset = new hashset<>(arrays.aslist(staffs)); list<string> result = new arraylist<>(staffsset);
如对本文有疑问, 点击进行留言回复!!
springmvc之ResponseBody响应json数据遇到的错误及解决
uni-app 后台升级 静默升级 uniapp 后台更新 静默更新 在线升级
SpringBoot多Module启动报错Could not transfer metadata
Hibernate项目报错:Cannot call sendError() after the response has been committed
网友评论