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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:02:23+00:00 2026-05-29T09:02:23+00:00

i have an arraylist and i want to add and remove many items at

  • 0

i have an arraylist and i want to add and remove many items at he same(almost) time. So i decide to create 2 methods. In the first method i implement the method which contains the remove part i use something like:

   //my list
   ArrayList<Human> list= new ArrayList<Human>(100);

   //Human is the object of the class Human
   List<Human> syncList = Collections.synchronizedList(new ArrayList<Human>());
   synchronized (syncList){

    for (Iterator<Human> iter = list.iterator(); iter.hasNext();) {
       Human = iter.next();
              -
              -
          //using the removes method of the iterator
          it.removes(something);

And in the second method (which i need to add many items) something like this:

            for(  ListIterator<Human> it = list.listIterator();it.hasNext();){  
            List<Human> syncList = Collections.synchronizedList(newArrayList<Human>());
        synchronized (syncList){
                   -
                   - 
          //using the add method of the iterator list
          it.add(something)

Now i realize that when those two void methods finished and the list called by another function don’t have the appropriate behaviour. I mean that some of the elements didn’t add or removed from the list. How can i fix this?any ideas?

  • 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-29T09:02:24+00:00Added an answer on May 29, 2026 at 9:02 am

    you are synchronizing on 2 entirely different objects, hence the inconsistent behavior. your call to synchronizedList() is returning a wrapper around the original list, on which you are synchronizing. since the 2 methods are using different wrappers, no actual synchronization is happening. you just need to synchronize on the original list implementation. of course, any other usage of the list member should also be synchronized.

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

Sidebar

Related Questions

I have an ArrayList<String> , and I want to remove repeated strings from it.
I want to add multiple BigInteger values to an ArrayList . All I have
I want to have an ArrayList where it contains HashTables. I create a Hashtable
I have a problem that I want to append or add a new arraylist
I have an arraylist where I want to add elements via a for loop.
I have an ArrayList<JCheckBox> that i want to convert to an ArrayList<String> First I
I have an ArrayList that I want to use to hold RaceCar objects that
I have some data stored as ArrayList . And when I want to backup
I have an arraylist that contains items called Room. Each Room has a roomtype
I have an ArrayList of type String that contain certain values. I want to

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.