- Home /
For all elements above a certain index
I'm trying to access all objects in a List above a certain index. The index I want is just a variable I have laying around, but I don't have a clear understanding of the For statement yet. I mean, I'm perfectly able to access ALL elements or elements that need a specific requirement too, but how can I access only the elements in the array above or beneath a certain index number?
Answer by Akill · Aug 06, 2012 at 12:49 PM
You say you can access all elements , so I assume you have seen this before :
for(int index=0;index < array.length;index++)
{
}
What this loop does is start at index =0 and keep incrementing index each time the for() statement is called (index++)..it will do this until index == array.length -1.
Now, you say you want to access all objects above a certain index, well, simply initialising the index variable to the index you want to start will work. So, instead of starting at index = 0 and looping through the entire array, you can start at say, index = 10 and then loop.
Clearly you will have to choose an index that IS less than array.length.
Perfect, I already did this before, but apparently I make some kind of mistake along the way. Thanks for reassuring me! Helped me out alot!
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
How do I check a List[0], when it's nothing? 1 Answer
How do I return the index of an array of sprites as an int? 1 Answer
Find specific element when duplicates exist in list. 1 Answer
What am I overlooking? -1 Answers