views:

200

answers:

2

for example I have an ArrayList with 2 elements, but Eclipse Java debugger shows me 10 elements where 3-10 are just nulls. How to disable this "feature"?

details on image

P.S.: Mac OS 10.5.6, Java6, Eclipse 3.4.2

+10  A: 

In the "Variables" view (as seen in your screenshot) click on the small downward triangle (=menu) in the top-right corner, select the "Java" sub-menu and then remove the tick in front of "Show null array entries".

(This sometimes does not work the first time. Probably a bug. Just try it until the null-values are gone in the view.)

Tobias Müller
I was going to suggest changing the detail formatter, but it wouldn't the right solution and I had never noticed the "show null array entries" option. +1
Paulo Guedes
+1  A: 

By Default when an ArrayList is created, its size is 10. Use ensureCapacity method of it to specify your capacity. this method should should be used if you have large nos of element to be added to arraylist, which helps in minimizing reallocation of memory chunks to when arraylist dynamically increases its size.

The negative ratings are very annoying. While not as on-topic as the best answer, this is still useful information. +1 to zero from me...
gatoatigrado