// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class ForLoops {
    public static void main(String[] args) {
        String[] sa = new String[2];
        try {
            for(String s : sa) {
                s = new String("ABC");
            }
            String s2 = sa[0].substring(0, 1);
            System.out.println("No exception");
        } catch(NullPointerException npe) {
            System.out.println("Exception");
        }
        try {
            for(int i = 0; i < sa.length; i++) {
                sa[i] = new String("ABC");
            }
            String s2 = sa[0].substring(0, 1);
            System.out.println("No exception");
        } catch(NullPointerException npe) {
            System.out.println("Exception");
        }
    }
}
