I have an array of Objects (file list excatly). How to iterate through this array and delete some Objects (in Java) – depending on the condition ?
File[] files = file.listFiles();
for(File f: files) {
if(someCondition) {
// remove
}
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
I think the best Java way to tackle your problem is to convert your array into a list and use an iterator which allows you to remove objects:
You can even convert it again into an array if necessary -even though handling a list is probably more convenient …: