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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:21:30+00:00 2026-06-02T19:21:30+00:00

I have tried to remove the list from a vector like below. public class

  • 0

I have tried to remove the list from a vector like below.

public class StringVectorTest {

private final List<String> stringVector = new Vector<String>();

@Test
public void listRemoveTest(){

    List<String> list = stringVector.subList(0, 2);

    stringVector.removeAll(list);

    Assert.assertEquals(stringVector.size(), 3);
}

@Before
public void fillList(){
    stringVector.add("ABC");
    stringVector.add("DEF");
    stringVector.add("GEH");
    stringVector.add("IJK");
    stringVector.add("LMN");
}

}

while i run the test i am getting the below error

java.util.ConcurrentModificationException
at java.util.SubList.checkForComodification(AbstractList.java:752)
at java.util.SubList.listIterator(AbstractList.java:682)
at java.util.AbstractList.listIterator(AbstractList.java:284)
at java.util.SubList.iterator(AbstractList.java:678)
at java.util.AbstractCollection.contains(AbstractCollection.java:82)
at java.util.Collections$SynchronizedCollection.contains(Collections.java:1563)
at java.util.AbstractCollection.removeAll(AbstractCollection.java:336)
at java.util.Vector.removeAll(Vector.java:853)

I know that i have to use an Iterator to overcome this ConcurrentModificationException can anyone please let me know how i should use it in a efficient manner / best practice?

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-02T19:21:31+00:00Added an answer on June 2, 2026 at 7:21 pm

    Do it as below:

    public void listRemoveTest() {
        stringVector.subList(0, 2).clear();
        Assert.assertEquals(stringVector.size(), 3);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Map<Something, List<String>> map . I want to remove a String from
I have tried the following two statements: SELECT col FROM db.tbl WHERE col (LIKE
i have a grid view with images populated from a list. when i remove
In my loop I am trying to remove items from a list that have
I have tried this... Dim myMatches As String() = System.Text.RegularExpressions.Regex.Split(postRow.Item(Post), \b\#\b) But it is
I have tried what seems like everything - I've done similiar things many times
I have a question regarding how to fetch a value from list item to
I want to completely remove error list from visual studio 2008, not disable it
I am trying to remove a string from a string in jQuery. Here is
How can we remove last comma from a comma seperated list in SQL query?

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.