LinkedList llist=new LinkedList();llist.add("..");...String[] str=new String[llist.size()];llist.toArray(str);這樣Object[]陣列就轉到了String[]陣列了,你可以去參考toArray()方法原型:public synchronized <T> T[] toArray(T[] a) { if (a.length < elementCount) a = (T[])java.lang.reflect.Array.newInstance( a.getClass().getComponentType(), elementCount); System.arraycopy(elementData, 0, a, 0, elementCount); if (a.length > elementCount) a[elementCount] = null; return a; }
LinkedList llist=new LinkedList();llist.add("..");...String[] str=new String[llist.size()];llist.toArray(str);這樣Object[]陣列就轉到了String[]陣列了,你可以去參考toArray()方法原型:public synchronized <T> T[] toArray(T[] a) { if (a.length < elementCount) a = (T[])java.lang.reflect.Array.newInstance( a.getClass().getComponentType(), elementCount); System.arraycopy(elementData, 0, a, 0, elementCount); if (a.length > elementCount) a[elementCount] = null; return a; }