提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
从数组创建向量
//来自 nowjava //package com.nowjava; import java.util.*; public class Main { public static void main(String[] argv) { Object[] array = new String[] { "1", "abc", "level", null, "nowjava.com", "asdf 123" }; System.out.println(createVector(array)); } public static Vector createVector(Object[] array) { return appendInto(new Vector(), array); } public static Vector createVector(Enumeration e) { Vector result = new Vector();/* 来 自 时 代 J a v a 公 众 号*/ while (e.hasMoreElements()) result.addElement(e.nextElement()); return result; } public static Vector appendInto(Vector v, Object[] array) { appendInto(v, array, array.length); return v; } public static Vector appendInto(Vector v, Object[] array, int quantity) { v.ensureCapacity(v.size() + quantity); for (int i = 0; i < quantity; i++) { v.addElement(array[i]); } return v; }