posted 17 years ago
Hello everyone,
I have an application. For example
***************************************
public class A{
ArrayList _arrayList;
public A(){
_arrayList = new ArrayList();
}
public method1(){
ArrayList _arr = new ArrayList();
_arr(someValue); // which is changes everytime.
_arrayList.add(_arr);
}
}
********************************
I my application i need to call my method1() more than 50,000 times. So it create 50,000 times create new _arr object.
So my question is that if i use following method2(), so is this efficient memory wise. IS this not create new Object on memory.
public class B{
ArrayList _arrayList, _arr;
public B(){
_arrayList = new ArrayList();
_arr = new ArrayList();
}
public method2(){
ArrayList _arr1 = _arr.clone();
_arr1 (someValue); // which is changes everytime.
_arrayList.add_arr1 );
}
}
***************************************
Please give me some suggestion which one is better, using clone method in class B, instead of creating new object in class A
thanks in advance