Issue With ArrayList

J

jagadesh

Hi Guys,

While i Was Working , I got to learn that
Defining an ArrayList with size is more better that defining it
without size

according to the performance Tips,

ArrayList my=new ArrayList(10);

works faster that ArrayList my=new ArrayList(10);

what is the difference and
Checking for null also takes much time when compared to the
performances.

is it true

Can u please Guide Me guys
 
R

Roedy Green

ArrayList my=new ArrayList(10);

works faster that ArrayList my=new ArrayList(10);

I think you meant:

ArrayList my = new ArrayList(10);
works faster than
ArrayList my = new ArrayList();

That is not true.

However:
ArrayList my = new ArrayList(100);
works faster than
ArrayList my = new ArrayList();
If you have 100 elements. However if you have only 10, then
ArrayList my = new ArrayList();
works faster.

new ArrayList() is just shorthand for new ArrayList(10).
They have exactly the same meaning.

Normally you specify the content type e.g.

ArrayList<String> my = new ArrayList<String>(100);
--
Roedy Green Canadian Mind Products
http://mindprod.com
Your old road is
Rapidly agin'.
Please get out of the new one
If you can't lend your hand
For the times they are a-changin'.
 
A

Arne Vajhøj

jagadesh said:
While i Was Working , I got to learn that
Defining an ArrayList with size is more better that defining it
without size

according to the performance Tips,

ArrayList my=new ArrayList(10);

works faster that ArrayList my=new ArrayList(10);

what is the difference and
Checking for null also takes much time when compared to the
performances.

is it true

No.

But you should not waste your time on microscopic optimizations
like this.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

ArrayList issue 2
Mutability issue 1
Issue with textbox script? 0
Issue with $_COOKIE 3
Having an issue with empty arrays 2
Implementing Many Stacks in the Same Program 1
Tasks 1
Issue with key down - JS 3

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,084
Latest member
HansGeorgi

Latest Threads

Top