5 Replies Latest reply on Oct 12, 2012 7:34 PM by 967860

# ArrayList Question

Hello all,

I understand that the Index must be less than the Size of the ArrayList, or the typical error message will be given:

"Problem occurred during processing: Index 1, Size: 1"

However, given the For Loop below and its consideration of the rule. Why did my program terminate after the ArrayList reached a size of 96, giving me the following message?

"Problem occurred during processing: Index 96, Size 96"

The program ran great until the ArrayList size reached 96. What could cause the Index to catch up to the Size after 3 days of runtime?

for(i=0; i<a.size(); i++)
{

}
• ###### 1. Re: ArrayList Question
>
However, given the For Loop below and its consideration of the rule. Why did my program terminate after the ArrayList reached a size of 96, giving me the following message?
>
Post the code that you are using.

Whether the for loop even does anything depends on how 'a' was created and initialized since a new ArrayList has a size of zero so the loop would not even execute unless you have first added something to the list.

And then you do understand that ArrayList's expand their capacity as needed indefinitely?

I run out of heap after about 25764000 iterations using this code
int i;
ArrayList a = new ArrayList();
for(i=0; i<a.size(); i++)
{
if ((i % 1000) == 0) {
System.out.println(i);
}
}
What is it you are trying to accomplish with the infinite loop? Are you trying run out of heap or trying to see what happens when the int reaches its maximum?
• ###### 2. Re: ArrayList Question

In response to your quoted statements, let me try to clarify.

"Whether the for loop even does anything depends on how 'a' was created and initialized since a new ArrayList has a size of zero so the loop would not even execute unless you have first added something to the list."

I initialized ArrayList 'a' and added the first element before the For Loop begins. For example:

int i;
ArrayList a = new ArrayList();

for(i=0; i<a.size(); i++)
{
if(x-y > z) {
}
}

"What is it you are trying to accomplish with the infinite loop? Are you trying run out of heap or trying to see what happens when the int reaches its maximum?"

I am not trying to run out of heap space or reach a maximum. I am simply trying to figure out why the size of 'a' stopped growing at 96. Why did the size of 'a' not increase to 97, 98, 99, and so on. Instead I received the following message after the size of 'a' reached 96:

"Problem occurred during processing: Index 96, Size 96"

Do you think this message was caused because I ran out of heap space, or do you think it was caused by something else?