import java.util.*;
public class TransferTest {
public static void main(String[] args) {
String[] aItems = {
"Bob", "Sue", "John", "Salley", "Vincent", "John", "Bob", "Sue"
};
String[] bItems = {
"Bob", "Jessica", "John", "Philip", "Salley", "Vincent", "Bob", "Ed"
};
Vector<String> a = new Vector<String>(Arrays.asList(aItems));
Vector<String> b = new Vector<String>(Arrays.asList(bItems));
Vector<String> selectednets = new Vector<String>();
// elements from vector b that are at the same index
// as equal elements in vector a
for (int i=0, n=a.size(); i<n; i++){
String onenode = (String)a.get(i);
if (!selectednets.contains(onenode)){
String secondnode = (String) b.get(i);
if (secondnode.equals(onenode)){
selectednets.add(secondnode);
}
}
}
System.out.println(selectednets);
selectednets.removeAllElements();
// Identify pairs of equal-value elements in a that occur in b
// at the same indices and copy the element into selectednets.
// Only the first occurrence of duplicates will be checked.
for (int i=0, n=a.size(); i<n; i++){
String onenode = (String)a.get(i);
for(int j = i+1; j < n; j++) {
String element = (String)a.get(j);
if(onenode.equals(element)) {
// Found duplicate value.
if(!selectednets.contains(onenode)){
String secondnode = (String) b.get(i);
if(secondnode.equals((String)b.get(j)) &&
onenode.equals(secondnode)) {
selectednets.add(secondnode);
System.out.println("Found " + onenode + " in a at " +
"indices " + i + " and " + j +
" and the matching\nvalue " +
secondnode + " in b at indices " +
i + " and " + j + ".");
}
}
}
}
}
System.out.println(selectednets);
}
}