转换字符串数组的java.util.List [英] Converting String array to java.util.List
本文介绍了转换字符串数组的java.util.List的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何转换字符串
阵列的java.util.List
?
解决方案
列表<串GT;字符串= Arrays.asList(新的String [] {一,二,三化});
这是的列表视图的数组中,列表是不可修改的一部分,你不能添加或删除元素。但时间复杂度为O(1)。
如果你想修改的列表:
列表<串GT;字符串=
新的ArrayList<串GT;(Arrays.asList(新的String [] {一,二,三化}));
这将从源阵列的所有元素复制到一个新的列表(复杂性:为O(n))
How do i convert String
array to java.util.List
?
解决方案
List<String> strings = Arrays.asList(new String[]{"one", "two", "three"});
This is a list view of the array, the list is partly unmodifiable, you can't add or delete elements. But the time complexity is O(1).
If you want a modifiable a List:
List<String> strings =
new ArrayList<String>(Arrays.asList(new String[]{"one", "two", "three"}));
This will copy all elements from the source array into a new list (complexity: O(n))
这篇关于转换字符串数组的java.util.List的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文