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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:09:32+00:00 2026-05-27T10:09:32+00:00

I have a question, Here is what I need to do – I have

  • 0

I have a question,

Here is what I need to do –

I have BankItems that are associated with numbers. I fill the list but when an objects enters that is $100 more than the lowest dollar value currently in the list, I want to delete the object that has the low value.

First – I create the list

    List<BankItem> listOfBankItems = new LinkedList<BankItem>();

Later in the program I create a new BankItem object and it to the list

listOfBankItems.add(createdItem);

and after adding each item I want to check to see if the new item is $100 more than any object already in the list so I run something like this

   for (int i = 0; i < listOfBankItems.size(); i++) {
    int oldValue =listOfBankItems.get(i).getAmount();
    int  newValue = createdItem.getAmount();
    int calculatedDif = newValue - oldValue;


    if (calculatedDif > 100) {
       listOfBankItems.remove(i); 
    }
}

Unfortunately, this isn’t working. I don’t know what it up. Maybe I shouldn’t use a LinkedList? Maybe my logic is way off-base. Please help.

Thanks!!!

  • 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-27T10:09:33+00:00Added an answer on May 27, 2026 at 10:09 am

    Your most significant issue probably relates to concurrent modification. For example, if element #49 is the one to be removed, once you remove it, the next element will now be #49, but you will be checking for #50 (as i was still incremented) – so you’re probably missing elements from your check.

    There are a few ways to handle this. You could remove the i++ from your for loop (leaving only the trailing semi-colon), then do this:

    if (calculatedDif > 100) {
       listOfBankItems.remove(i); 
    } else {
       i++;
    }
    

    Alternatively, you could use an Iterator and its remove() method, which would handle this for you automatically.

    You can also improve the performance of this by not obtaining newValue and recalculating calculatedDif on every step of the loop. Declare these 2 lines above the for loop.

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

Sidebar

Related Questions

very simple question here but I don't have the answer... ;-) I just need
Just a quick question here. I have a program in which I need to
C# question here.. I have a UTF-8 string that is being interpreted by a
I have an other active question HERE regarding some hopeless memory issues that possibly
Alright. So I asked a question here but I feared that I anwsered it
I have the following question here I need to understand the following MIPS disassembling
Actually, I have a design question here. Its very simple but the point is:
I have a somewhat obscure question here. What I need: To determine if the
I have a simple question here. I need to UPDATE a row table by
I have posted a question on here previously asking similar advise, but this project

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.