Q:

Java: Iterating HashMap - Algorithm needed

I have a list of names, say 8 names: Joe, Bob, Andrew, Bill, Charlie, Sarah, Ann, Victor
The count of names might differ**.
1) What should I use as name list? Hashmap, Vector, Hashtable, List, ArrayList?
2) I need to match them up like this: Joe-Bob, Andrew-Bill, Charlie-Sarah, Ann-Victor. Could you please show me an example how to make a loop which would do so?
Thank you!

A:

Hashmaps have no order. If you want to insert a list of names like you want, you'd do something like the following (with an array):
for(int i = 0; i < myArray.length - 1; i += 2) {
    hashMap.add(myArray[i], myArray[i+1]);
}

