Java Convert Object[] Array to Vector

后端 未结 6 2038
灰色年华
灰色年华 2020-12-16 19:21

What\'s the best way to convert an Object array to a Vector?

JDE < 1.5

public Vector getListElements()
{
  Vector myVector = this.elements;
  retu         


        
6条回答
  •  没有蜡笔的小新
    2020-12-16 20:10

    imho your only viable option is:

    public Vector getListElements()
        Vector vector = new Vector(this.elements.length);
    
        for (int i = 0; i < this.elements.length; i++) {
            vector.add(this.elements[i]);
        } 
    
        return vector;
    }
    

提交回复
热议问题