将矢量转换为列表 [英] convert vector to list
本文介绍了将矢量转换为列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将矢量转换为列表?
How to convert a vector to a list?
推荐答案
Vector
是一个实现<的具体类a href =http://java.sun.com/javase/6/docs/api/java/util/List.html =noreferrer> 列表
接口在技术上它已经是列表
。你可以这样做:
Vector
is a concrete class that implements the List
interface so technically it is already a List
. You can do this:
List list = new Vector();
或:
List<String> list = new Vector<String>();
(假设 Vector
字符串
s)。
但是如果你想将它转换为 ArrayList
,这是最接近的列表
实现Java Collections Framework中的`Vector~然后就这样做:
If however you want to convert it to an ArrayList
, which is the closest List
implementation to a `Vector~ in the Java Collections Framework then just do this:
List newList = new ArrayList(vector);
或通用版本,假设 Vector
字符串
s:
or for a generic version, assuming a Vector
of String
s:
List<String> newList = new ArrayList<String>(vector);
这篇关于将矢量转换为列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文