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,736
  • 4
  • 55
  • 80
Devrath
  • 42,072
  • 54
  • 195
  • 297

0 Answers0