Re: ArrayList issue
On Sun, 21 Feb 2010 16:45:37 -0800 (PST), francan
<francan00@yahoo.com> wrote, quoted or indirectly quoted someone who
said :
I have this test working where it takes data from a Java class and
shows it in a JSP:
String targetItems = "test";
List pageItems = New ArrayList;
This could not have compiled. new is always lower case.
ArrayList needs ( n );
for(int i = 0;i < calculatedResults + 10;i++)
{
pageItems.add(targetItems + " " + i)
}
request.setAttribute(pageItems, "pageItems");
I would like to stop using test and put real data in using
an ArrayList but my attempt outputs a huge array of info for each
record:
ArrayList<TargetBean> targetItems = New ArrayList<TargetBean>
(TargetListing.getList());
If TargetListing has starts with a capital letter, it SHOULD be the
name of class, making getList a static method.
List pageItems = New ArrayList;
Again this could not have compiled.
for(int i = 0;i < calculatedResults + 10;i++)
{
pageItems.add(targetItems + " " + i)
to do this, you should declare:
ArrayList<String> pageItems = new ArrayList<String>(
calculatedResults+10);
But since you know the precise size in advance, you could in many
circumstances use an array which is many times faster.
}
request.setAttribute(pageItems, "pageItems");
It is best to cut and paste compilable code rather than composing off
the top of your head. You introduce additional errors which complicate
the issues.
See http://mindprod.com/jgloss/arraylist.html
for sample code.
--
Roedy Green Canadian Mind Products
http://mindprod.com
When a newbie asks for help tracking a bug in a code snippet, the problem is usually is the code he did not post, hence the value of an SSCCE.
see http://mindprod.com/jgloss/sscce.html