<分区>
Possible Duplicate:
clone utility for HashMap in java
我有一个一对一的 map :
HashMap<Integer, ArrayList<Double>> matrix;
Integer 是索引,ArrayList 的维度约为 50。索引的大小可能高达一百万。我想尽快复制它(包括 Arraylist 值)。
我做了以下操作:
public Map<Integer,ArrayList<Double>> getCloneOfMatrix(){
Map<Integer, ArrayList<Double>> newMatrix = new HashMap<Integer,ArrayList<Double>>();
for(int i=0 ; i < indexSize; i++){
ArrayList<Double> arrList = new ArrayList<Double>();
arrList=(ArrayList<Double>) matrix.get(i).clone();
newMatrix.put(i,arrList);
}
return newMatrix;
}
我发现它在计算上很昂贵,有什么方法可以更快地做到这一点。