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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:59:12+00:00 2026-06-12T09:59:12+00:00

Is this going to cause unpredictable behavior? ArrayList<X> x = new ArrayList<>(); //x.add(new X())…

  • 0

Is this going to cause unpredictable behavior?

 ArrayList<X> x = new ArrayList<>();
 //x.add(new X())...
f:
for(int i = 0; i < x.size() -1;)
{
      X y = x.get(i);
      for(int j = i + 1; j < x.size();)
       {
          if(a) {
           x.remove(j);
           continue;
          }
          if(b) {
           x.remove(i);
           continue f;
          }
          j++;
        }
       i++;
}
  • 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-12T09:59:13+00:00Added an answer on June 12, 2026 at 9:59 am

    I don’t think it will be unpredictable, but your style seems wrong to me, so your approach is suspect.

    Using a label is a bad idea, and deciding to use it shows that your approach is flawed.

    You may want to look at this discussion about deleting on ArrayList, but basically, LinkedList would be fsster:

    http://www.velocityreviews.com/forums/t587893-best-way-to-loop-through-arraylist-and-remove-elements-on-the-way.html

    But, removing this way will work.

    UPDATE:

    Oops, just saw a couple of bugs:

          if(a) {
           x.remove(j);
           continue;
          }
    

    OK, in this one, you will go back through the loop for j, but you didn’t increment j.

          if(b) {
           x.remove(i);
           continue f;
          }
    

    This is the same for i.

    So, you need a similar change to fix it:

    for(int i = 0; i < x.size() -1; i++)
    

    This way, when you hit continue then it will still go to the next element.

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

Sidebar

Related Questions

Is this going to cause memory issues with Ruby. I know Open-URI writes to
Is this going to cause me untold grief if I stick it at the
Yesterday while going through this question, I found a curious case of passing and
This is going to be a bit difficult to explain. I'm usually fine with
This is going to be a stupid question but I have spent an inordinate
This is going to sound too silly / too basic - sorry about that,
This is going to be a long post and just for fun, so if
This is going to be a quick discussion, but I just wanted some feedback
Hey this is going to be one of those dumb questions. I am trying
I'm guessing this is going to involve regexp or something, but I'll give it

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.