I have (for this example) two ArrayList
s. A plaintext alphabet and an enciphered alphabet. I want to take a letter from the plaintext alphabet and get the letter from its' corresponding index from the enciphered alphabet. However, it always returns the index as -1, even if the entry exists.
public class Rotor {
String currentIndex;
private ArrayList rotorType = new ArrayList();
private ArrayList control = new ArrayList();
private final char[] alpha = new char[]{
'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U',
'V', 'W', 'X', 'Y', 'Z'};
static char[] I = new char[]{
'E', 'K', 'M', 'F', 'L', 'G', 'D', 'Q',
'V', 'Z', 'N', 'T', 'O', 'W', 'Y', 'H',
'X', 'U', 'S', 'T', 'A', 'I', 'B', 'R',
'C', 'J'};
public Rotor(char[] rotor) {
for (int i = 0; i < 25; i++) {
rotorType.add(rotor[i]);
control.add(alpha[i]);
}
}
public void convert(String nextCharacter) {
currentIndex = String.valueOf(rotorType.get(control.indexOf(nextCharacter)));
}
}
What would cause this to return index -1?