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

  • SEARCH
  • Home
  • 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 8623417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:16:32+00:00 2026-06-12T07:16:32+00:00

So I want to insert a value in a specific index, that mean I

  • 0

So I want to insert a value in a specific index, that mean I would throw exception if the index I want to insert is not exist or bigger than size, otherwise, I would use this method to ensure the capacity of the array is not null:

private void ensureCapacity(int size_wanted)
{
  int max_capacity = storage.length;
  if (size_wanted > max_capacity) 
  {
    max_capacity = max_capacity * GROW_FACTOR +1; 
    storage = Arrays.copyOf(storage, max_capacity); // increases array size + copy contents
  } 
}

Then at this point, I suppose to extend the array and already made a copy of my original with the increased size already, right?

All I need to do is using a loop and shift everything to the right by one, to leave space for the index I want to insert at, correct?

  • 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-06-12T07:16:33+00:00Added an answer on June 12, 2026 at 7:16 am

    You can use System.arrayCopy to move array like that.
    but why are you rebuilding existing functionality provided by ArrayList

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

Sidebar

Related Questions

I want to insert the following as the value for a variable in some
i want to set the value to a insert query from select query ,how
I want to check a Column value when update.If its match insert into another
I want to insert column1 from table1 to column1 in table2. If the value
I want to remove element from queue with specific value. How to do such
I want to INSERT VALUES after user has clicked OK on the confirmation box.
I have the following table: I want to insert values from the MySQL workbench.
I have the following code below which works, but I want to insert values
i want to insert the values of two arrays into a table in a
I want to insert row for each day to add new values, and I

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.