Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialloxton
237 PointsSize of array after resizing?
I do not understand how the size of the array after resizing is 8. How do you come to this conclusion?
ArrayBag b = new ArrayBag();
for (int i = 1; i <= 18; i++) {
b.add(i);
}
for (int i = 1; i <= 15; i++) {
b.remove(i);
}
1 Answer
Steven Parker
231,248 PointsThey're talking about the storage size, and not the number of active elements. You didn't provide a link to the course page, but it should have told you about how space is not allocated (or de-allocated) on a per-item basis, but in clusters that are powers of 2 in size. So when you get down to 3 items, the last allocation threshold was 4, and with de-allocations retaining double the size in use, that would make 8.