Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Computer Science

Size 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++) {
for (int i = 1;  i <= 15; i++) {

1 Answer

Steven Parker
Steven Parker
216,096 Points

They'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.