Possible Duplicate:
clone utility for HashMap in java
I have an one to one map as:
HashMap<Integer, ArrayList<Double>> matrix;
Integer is index and ArrayList has dimnesion of about 50. Index may have size upto one million. I would like to make copy(including Arraylist value) of it as soon as possible.
I did following:
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;
}
I found it computationally expensive, is there any way to do it in faster way.