Question: I'm really good with VB and I have a project where I need to check an array. If the same item in an array exists twice or more it needs to be changed to an item that doesn't exist. Now I'm in a class where they're making us use Java for this project. 

I was wondering what is the equivalent of a for each loop in Java? I checked the JavaDocs and it only had info for the regular for loop, I didn't notice any section that said anything about a for each loop.

Answer: 
It's more subtle in Java than VB. You can find the official docs in the Oracle documentation here (towards the bottom):

[Java For Loops](https://docs.oracle.com/javase/1.5.0/docs/guide/language/foreach.html)

The provided example is:

```
// Returns the sum of the elements of a

int sum(int[] a) {
    int result = 0;
    for (int i : a)
        result += i;
    return result;
}

```

Hope that helps. Be careful not to remove or add elements inside the loop or you will get a Concurrent Modification Exception.
A `for each` loop (also known as `the enhanced for loop`) is as follows:

```
for (String name : names) {
    // here, the loop will work over each element of 'names',
    // with the variable name with which to access each element
    // being 'name', and output it
    System.out.println(name);
}

```

A normal `for loop` is as follows:

```
for (int i = 0; i < max; i++) {
     // here, i will iterate until max, then the loop will stop.
     // any array access here has to be done manually using i, which increments.
}

```

If insertion order from the names array is important, keep adding the objects to a [`LinkedHashSet<String>`](http://docs.oracle.com/javase/7/docs/api/java/util/HashSet.html), then with either a for loop or enhanced for loop or iterator, go over your list of names and add each of them to the `LinkedHashSet`. If the `add` method, passing in your name, returns `false`, generate a new name and add that.

If insertion order is not important, use a `HashSet<String>` instead.

At the end, convert back to an array if it is important (`String[] bla = map.toArray(new String[0])`), or output the `toString()` of the map.