Solved

How to add an element to an existed list?

Posted on 2006-10-20
2
227 Views
Last Modified: 2010-03-31
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?
0
Comment
Question by:chenwei
  • 2
2 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 30 total points
ID: 17772780
newList.addAll(oldList);
newList.add(neEle);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17772816
:-)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
replace a word with other 1 44
Groovy problem when using SOAPUI : DispatchException occurred 7 44
check java version using powershell 13 92
String array comparison 4 33
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question