当前位置:网站首页>Convert string array to list collection

Convert string array to list collection

2022-06-25 02:00:00 Full stack programmer webmaster

Hello everyone , I meet you again , I'm your friend, Quan Jun .

String[] arr = {"a", "C", "abc"};
		// asList   This method can directly convert an array into list aggregate , But the collection is  [ read-only ], You cannot add, delete, or modify the resulting set 
List<String> asList = Arrays.asList(arr);
System.out.println(asList);  //  result :[a, C, abc]
List list = new ArrayList(asList);// After this step, you can add, delete and modify 
list.add("ddd");
System.out.println(list);// The result is [a,b,ccc,ddd]

Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/151785.html Link to the original text :https://javaforall.cn

原网站

版权声明
本文为[Full stack programmer webmaster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206242153197987.html