How to add an element to an existed list?

chenwei
chenwei used Ask the Experts™
on
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?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
newList.addAll(oldList);
newList.add(neEle);
Top Expert 2016

Commented:
:-)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial