Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6062111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:00:50+00:00 2026-05-23T09:00:50+00:00

I have an empty mutable array. Is it possible to insert object at index

  • 0

I have an empty mutable array. Is it possible to insert object at index 2 for example, while there’s nothing at index 0 and 1? I mean to increase capacity dynamically or something like that. .Regards.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:00:51+00:00Added an answer on May 23, 2026 at 9:00 am

    NSMutableArray is not a sparse array; it does not allow empty slots that can be filled in later. initWithCapacity: just hints to the array that it will be filled to a certain amount; it isn’t generally necessary in practice and, unless you know exactly how many items you are going to shove in the array, don’t bother calling it (just use init).

    A mutable array will quite efficiently grow in size as objects are added.

    If you need a data structure that supports “holes”, then either use something else or put a placeholder object in the slots that are supposed to be empty.

    I.e. if you wanted an array with 10 slots, you might do:

    NSMutableArray *a = [NSMutableArray array];
    for(int i = 0; i<10; i++) [a addObject: [NSNull null]];
    

    You can then check if the retrieved object isEqual: [NSNull null] to know if the slot is empty or not. And you can use replaceObjectAtIndex:withObject: to stick an object at a specific index.

    Or you could use a different data structure; a dictionary with the indices as the keys would work, for example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an empty JTable, absolutely nothing in it. I need to dynamically generate
I have an empty TextView set for my ListView . When there is no
Is there a way to make a non-resizeable vector/array of non-reassignable but mutable members?
In my index.html page, I have an empty table defined as following: <body> ...
I am generating an Excel file through MATLAB and I have empty cells in
I have files which have many empty cells which appear as NaNs when I
If I have an empty tag: <tag/> How can I add text so that
Let's say I have an empty XML file like so: <root></root> And I want
Hey all, basically i have an empty AS3 fla file with just the following
I have dragged a empty asp.net table onto my webform. I generate all the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.