I have an “do – while” loop with 5000 numbers that should get added to an array during each run through the loop like this:
The problem is that every time the loop is executed, the numbers get overwritten and only the last runthrough of data is in the array once the loop finishes.
I use this code:
long cursor = -1;
long[] fArray = new long[100000]; // more than enough space in array
IDs ids = twitter.getFollowersIDs(name, cursor); // start with first page of 5000 numbers
do
{
ids = twitter.getFollowersIDs(name, cursor);
fArray = twitter.getFollowersIDs(name, cursor).getIDs(); // this gets Array with 5000 numbers every time until "empty"
cursor = ids.getNextCursor(); // jump to next array with 5000 new numbers
} while (ids.hasNext());
You are always only writing into the first 5000 elements of your very huge array.
Instead you want to assign the result of the getFollowersIDs() call to a separate local array and afterwards use arraycopy to copy the 5000 current followers into the much larger array of all followers.