• Post Reply Bookmark Topic Watch Topic
  • New Topic

Eliminating A ConcurrentModification Exception  RSS feed

 
Jason Ferguson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!