ArrayList clear() clearing multiple lists

I have a program that is using controlP5 to add-to and remove a list of objects from various other lists of objects. The problem I am having currently is that clearing a list clears multiple lists for no apparent reason. So listA.clear() clears listA, listB, listC ect even if there is no relationship between the lists. This is the event handler for controlP5 where the clear methods are being called.

public void controlEvent(ControlEvent theEvent) 
{  
  if (theEvent.isFrom(checkbox)) 
  {      
    filteredData.clear();

    if (checkbox.getArrayValue()[0] == 1)
    {         
      listFilter.filterByCityMaint();
      filteredData.addAll(listFilter.getCityMaint());
    }    
    else if (checkbox.getArrayValue()[1] == 1)
    {   
      listFilter.filterByDMV();   
      filteredData.addAll(listFilter.getDMV());
    }
    else
    {
      filteredData = unfilteredData;          
    }
  }
} 

Has anyone else experienced this problem? or Is there something wrong with the method that I am using to modify this list?

Answers

  • Answer ✓

    Perhaps you have assigned one list to another, thinking it will copy its content?

    It is a rather common error...

    Limited to guesses, as you don't show the other lists, etc.

  • Ahh wow, I had no idea that could happen but that is exactly what is going on. Thanks!!!

Sign In or Register to comment.