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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:23:21+00:00 2026-06-11T03:23:21+00:00

I have three List<String> variables: classFiles , usernames , and fileDirectories . I have

  • 0

I have three List<String> variables: classFiles, usernames, and fileDirectories. I have a String (a list of strings but I will be comparing every string in the list with the loop below) that consists of one item from each of the lists. I want to loop through all three lists and check if one value from all three of the lists are in the String

What would be the best way to go about this?

for(String classFile:classFiles) {
//if contains classfile statement
  for(String username:usernames) {
  //if contains username statement
    for(String fileDirectory:fileDirectories) {
      //if contains filedirectory statement
    }
  }
}

or

for(String classFile:classFiles) {
  for(String username:usernames) {
    for(String fileDirectory:fileDirectories) {
      //if statement
    }
  }
}

or

for(String classFile:classFiles) {
  //make list of files that contain classFile
}

for(String username:usernames) {
  //remove items from list that do not contain username
}

for(String fileDirectory:fileDirectories){
  //remove items from list that do not contain fileDirectory
}

Or is there a better way to do this?

EDIT: Example

classFiles - a1, a2, a3
usernames - noc1, noc2, noc3
fileDirectories - C:/projects/a1/noc1/example.java, C:/projects/a1/ad3/example.java

and the string to check

String - C:/bin/a1/noc1/example.class

what i want to do is if both the fileDirectory and String contain a classFile and username, then add it to a list

so in this example C:/bin/a1/noc1/example.class will be added to the list but C:/bin/a4/fd1/example.class wont be or C:/bin/a3/noc3/example.class would not be added

  • 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-11T03:23:23+00:00Added an answer on June 11, 2026 at 3:23 am

    When you perform remove operations for-each loop is not best choice. You should use Iterator and remove on iterator to avoid concurrent modification exception.

    Instead

    for(String fileDirectory:fileDirectories){
      //remove items from list that do not contain fileDirectory
    }
    

    You should do something like

    Iterator iter = fileDirectores.iterator();
    while(iter.hasNext())
    {
    //Get next
    //Do your check 
    iter.remove();
    }
    

    This leads to having three separate iterates to full fill your requirement.

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

Sidebar

Related Questions

I have these three lists with the same number of elements List<String>competitoinsIDs = new
I have a list of strings in kumo . I am printing three strings.
I have a list of objects. These objects have three variables, ID, Name, &
I have a List and it is filled with strings like this: List<string> data
In C#, say I have a class called Note with three string member variables.
I have three different List collections. How can I show them in one ListBox
I have three lists that I want to convert into one list. When I
i have one problem with handling list,i have three class named as UserInf,userData,userProcess,i created
I have three lists, I need to move Animal object from list animalSource to
I have a list of MyObjects which I need to divide into three groups:

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.