0

(I believe this is not a duplicate question!!). I am trying to iterate over a arrayList, do some manipulation and add elements to the same arrayList inside the for each loop.

I want to see the results while iterating.

I am ending up with ConcurrentModification Exception.

        for(String ex55 : firstListOfOptions)
    {
        Criteria crteria4 = session.createCriteria(Delays.class)
                .add(Restrictions.eq("programName", ex55));

        List<Delays> delaysList = crteria4.list();

        for(Delays dlys : delaysList)
        {
            if(!dlys.getProgramCalls().contentEquals(" "))
            {
            System.out.println(dlys.getProgramCalls());
            String[] resultSet = dlys.getProgramCalls().split(",");
            for(String rs : resultSet)
            {
                firstListOfOptions.add(rs);
            }
            }
        }


    }

How do I avoid this issue. Many thanks!

Gowtham
  • 364
  • 2
  • 5
  • 16
  • 1
    Modify and add object to a different list as you iterate. – callyalater Aug 10 '16 at 18:02
  • http://stackoverflow.com/questions/13133688/java-util-concurrentmodificationexception-when-adding-another-object – azurefrog Aug 10 '16 at 18:02
  • do you want to see the changes you've made to the list as you iterate? if not, you could create a copy of the initial list and iterate over that or alternatively construct a distinct new list for results – obataku Aug 10 '16 at 18:03
  • I do want to see the changes I made to the list as I am iterating. – Gowtham Aug 10 '16 at 18:43

0 Answers0