http://stackoverflow.com/questions/689370/java-collections-copy-list-i-dont-understand

若想要複製 collections
那要用下列方法:

List
<String> b =newArrayList<String>(a);

creates a shallow copy of a within b. All elements will exist within b in the exact same order that they were within a (assuming it had an order).

 

不能用以下方法,會失敗因為雖然給了a.size,但實際上b的size還是0,不同size不能做copy。

// note: instantiating with a.size() gives `b` enough capacity to hold everythingList<String> b =newArrayList<String>(a.size());Collections.copy(b, a);
arrow
arrow
    全站熱搜

    pcwiki 發表在 痞客邦 留言(0) 人氣()