convert vector to list

后端 未结 2 1889
一整个雨季
一整个雨季 2021-02-05 04:26

How to convert a vector to a list?

2条回答
  •  青春惊慌失措
    2021-02-05 04:44

    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();
    

    or:

    List list = new Vector();
    

    (assuming a Vector of Strings).

    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);
    

    or for a generic version, assuming a Vector of Strings:

    List newList = new ArrayList(vector);
    

提交回复
热议问题