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 9060189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:09:44+00:00 2026-06-16T15:09:44+00:00

I am making a array list of items and changing its contents occasionaly.The problem

  • 0

I am making a array list of items and changing its contents occasionaly.The problem is that after removal of an item from the array list,the sequence of items become destorted and the array list looses its sorting.I searched a lot but did not get any idea about how to keep the array list sorted after removal of items from it.This is the code i am using:

ArrayList<String> m_namesOfContactsArrayList = new ArrayList<String>();

for(int i = 0;i < 100;i++)
m_namesOfContactsArrayList.add(i);

This is where i am removing the items:

m_namesOfContactsArrayList.remove(3);
m_namesOfContactsArrayList.remove(4);
m_namesOfContactsArrayList.remove(5);

Please help me.Thanks in advance.

  • 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-16T15:09:45+00:00Added an answer on June 16, 2026 at 3:09 pm

    Deletion of an element doesn’t affect the order of the elements.

    Just to demonstrate it on your code:

    ArrayList m_namesOfContactsArrayList = new ArrayList();

    for(int i = 0;i < 10;i++)
        m_namesOfContactsArrayList.add(""+i);
    
    System.out.println(m_namesOfContactsArrayList);
    
    m_namesOfContactsArrayList.remove(3);
    m_namesOfContactsArrayList.remove(4);
    m_namesOfContactsArrayList.remove(5);
    
    System.out.println(m_namesOfContactsArrayList);
    

    Before removal:
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

    After removal:
    [0, 1, 2, 4, 6, 8, 9]

    The three elements are gone, but the list is still sorted.
    Btw, the java List is intended to be sorted by the insertion order. If you want to order the elements by some specific criteria, you can use e.g. a SortedSet, like TreeSet

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

Sidebar

Related Questions

I had a problem that was making the original array to change, the curious
I have a method that takes a condition and item, from an array of
I have some code that produces undefined values in an array making no sense.
I'm really confused with an array im making, its gotten a bit confusing to
I m making a Shooting game, in that I want an array of ImageViews
If I have a list(or array, dictionary....) in python that could exceed the available
I'm using Backbone.js to display a list of items (stations) from an API request.
I'm making an app that creates new files, there's no problem when I name
Im making a little shopping list app. In the app, if an item in
I need to sort a list who's items are objects that describe how 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.