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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:40:31+00:00 2026-06-11T11:40:31+00:00

String input from keyboard Vector<String> myVector = new Vector<String>(someArray.length); //assume Vector is populated Iterator<String>

  • 0
String input from keyboard
Vector<String> myVector = new Vector<String>(someArray.length);   //assume Vector is populated
Iterator<String> itr = myVector.iterator();

for loop begins
    while(itr.hasNext() && itr.next().equals(input)){
       itr.remove();
    }

    ...

    while(itr.hasNext()    // is this the problem source?
     run more code  

for loop ends

when the current element equals to a string input, i want to remove that element, otherwise continue iterating. i keep getting concurrent exceptions here.

what else should i do? should i be moving my itr.next elsewhere?

QUESTION: i want the logic such that if the current Vector element equals to target, i want it removed from the Vector. how can i do that?

  • 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-11T11:40:32+00:00Added an answer on June 11, 2026 at 11:40 am

    I do not know why you are getting concurrent modification exceptions, because removing items through an iterator is legitimate: according to the documentation,

    If the Vector is structurally modified at any time after the Iterator is created, in any way except through the Iterator’s own remove or add methods, the Iterator will throw a ConcurrentModificationException.

    To answer your question about removing from the vector all elements that are equal to target, the simplest solution is to use Vector‘s removeAll method.

    myVector.removeAll(Collections.singletonList(input));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to input a string or number from the keyboard and then display
i want to replace last input character from keyboard to '' My String Input
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.in(Standard input stream)- gets the input from keyboard
I have a string input from which I need to extract simple information, here
I'm having trouble separating numbers and characters from my input string. The purpose of
Not parsing the parameters in the beginning but parse the input string read from
In my project i need to take an expression input from user as string
I am trying to match words driven from a database in a string input
I’m trying to write a regex/method that extracts Variables from an input String that
i want to pass a string from an input box that after submition automatically

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.