0

I have a function to remove the duplicates in a collection.

/** Remove the duplicates **/
private List<Topic> removeDuplicateEntries(List<Topic> mlist) {

    List<Topic> allEvents = mlist;
    List<Topic> noRepeat = new ArrayList<Topic>();

    for (Topic event : allEvents) {
          boolean isFound = false;
          // check if the event name exists in noRepeat
          for (Topic e : noRepeat) {
                if (e.getUserId().equals(event.getUserId())){
                    isFound = true;
                    break;
                }
           }
           if (!isFound) noRepeat.add(event);
    }

    return noRepeat;
}

Whats happening is sometimes I get the error

java.util.ConcurrentModificationException
   at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:573)
   at com.sttarter.communicator.CommunicatorDBHelper$1.run(CommunicatorDBHelper.java:54)
   at java.lang.Thread.run(Thread.java:818)
savepopulation
  • 11,248
  • 4
  • 53
  • 71
Devrath
  • 39,949
  • 51
  • 178
  • 266

0 Answers0