• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Eliminating A ConcurrentModification Exception

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I should have known better, but didn't...

I have the following method in a ViewHelper class. This class acts as a bean used by a JSP, so it cannot have any parameters.

public List<Project> getActiveProjectsByCsrdNumber() {

List<Project> projectList = null;
try {
projectList = projectService.getActiveProjects();
for (Project project : projectList) {
if (project.getProjectCsrdNumber() == null) {
projectList.remove(project);
}
}
Collections.sort(projectList, new ProjectCsrdNumberComparator());
} catch (Exception e) {
e.printStackTrace();
log.debug(e.toString());
}

return projectList;
}

The idea is that the method gets a List of Project objects, then iterates through looking for ones that have a particular blank field (which I want to filter out).

I suppose I can build a second collection of "bad" Project objects, and once the iteration is complete, remove the second collection from the first.

Is there a better way?

Jason
 
Jason Ferguson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never mind, I was an idiot...

I should have called the iterator's remove() method, not the List's remove() method.
 
reply
    Bookmark Topic Watch Topic
  • New Topic