Q:

Getting ConcurrentModificationException when I got no extra thread running

The following method works if I declare the Iterator inside the method. If I declare it outside the method, it causes a ConcurrentModificationException. I do not have any other thread running for any concurrent operations. I don't get why the difference between declaring it inside and outside the method. I could get away with declaring the iterator in every method but feel that is not efficient. Please advice what is wrong. Thanks. 
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Scanner;

public class Linker {

    private static LinkedList<String> list = new LinkedList();

    public static void main(String[] args){
        load("sample.txt");
        find("Sam");
    }

    public static void load(String sourceName){
        try {
            Scanner in = new Scanner(new File(sourceName));
            while (in.hasNextLine()){
                String name = in.nextLine();
                list.add(new String(name));
            }
            in.close();
        }catch (FileNotFoundException e){
            System.out.println("File not found.");
        }
    }

    //static ListIterator<String> iterator = list.listIterator(); //causes ConcurrentModificationException
    public static int find(String name){
        ListIterator<String> iterator = list.listIterator();//this works
        while (iterator.hasNext()){
            String x = iterator.next();
        }
        return -1;
    }
}

A:

Lists in Java work on a mod count.  That is, before letting anyone use the ListIterator, store the modcount at the moment of creation.  Then when iterating check to see if the modcount at the moment of creation is greater than current modcount.
What you are doing, is creating a ListIterator prior to population of the list setting the List's current modcount to 0.
private List<String> list = new ArrayList<>();
private ListIterator<String> itr = list.listIterator(); //at this point mod count is 0

public static void load(String sourceName){
        list.add("Foo");// increment mod count by 1
}

So any modifications after load, will increase the modcount by 1.  And since the modcount was 0 prior to creating the ListIterator, any iterator invocation will throw a comodification. 
An alternative solution is to create the ListIterator after the load method is finished adding. At that point the modcount will not change.

