I need to port code from blackberry to android and facing small problem: Example: the bb code is:
public class MyClass{
private MyObject[] _myObject;
public void addElement(MyObject o){
if (_myObject == null){
_myObject = new MyObject[0];
}
Arrays.add(_myObject, o);
}
}
unfortunately android does not have Arrays.add()
which is part of net.rim.device.api.util.Arrays
(static void add(Object[] array, Object object)
)
Is there any replacement for android to dynamically extend and append in to simple array so I don't change the rest of my code.
I tried to write my own utility but it does not work:
public class Arrays {
public static void add(Object[] array, Object object){
ArrayList<Object> lst = new ArrayList<Object>();
for (Object o : array){
lst.add(o);
}
lst.add(object);
array = lst.toArray();
}
}
.. after I call
public void addElement(MyObject o){
if (_myObject == null){
_myObject = new MyObject[0];
}
Arrays.add(_myObject, o);
}
the _myObject
still contain 0 elements.