chenwei
asked on
How to add an element to an existed list?
Assumed I have an existed list, how can I add an element to it at run time? I do as follow:
...
List newList = new ArrayList();
List oldList = myObject.getList();
MyElement newEle = new MyElement();
for(int i=0; i<oldList.size(); i++)
newList.add(oldList.get(i) );
newList.add(neEle);
...
I think this way seems not so elegent. Someone has any better idea?
...
List newList = new ArrayList();
List oldList = myObject.getList();
MyElement newEle = new MyElement();
for(int i=0; i<oldList.size(); i++)
newList.add(oldList.get(i)
newList.add(neEle);
...
I think this way seems not so elegent. Someone has any better idea?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:-)