I’ve a list of strings Dad, mam, Junior, Richard. Let’s say, I remove Junior whose index is 2 from the list. Is richard’s index becomes 2 or is still 3 with a gap at the second position?
Thanks for helping
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
No gap. If you want a gap replace the value at that position with
nullyourself.Mostly you don’t want a gap, so you can be happy that it’s kept tidy for you.
One practical consequence though, is that if you are going to be removing a lot of items in the same operation, you may find it faster to build a new list with only those you aren’t removing (because it moves things around internally after each remove).
It has to be a lot for that to be worth while though. Bear it in mind if you hit a big delay, rather than jumping straight into taking that approach first thing.