Hi,
So I have this basic mail forwarding program and I'm running into a big issue with regards to the loop that I'm using.
String name = input.next();
String mailingAddress = input.next();
iterator = entries.iterator();
for (int i = 0; i < entries.size(); i++)
{
String[] otherEntryInfo = (iterator.next().split(";"));
String otherName = otherEntryInfo[0];
String oldAddress = otherEntryInfo[1];
String newAddress = otherEntryInfo[2];
if (name.equals(otherName) && mailingAddress.equals(oldAddress))
{
mailingAddress = newAddress;
}
}
System.out.println("Send to " + mailingAddress);
input.next() is a Scanner that reads the next user input
entries is a linked list of Strings that have the format name;oldAddress;newAddress
iterator.next() gives the next String in the linked list
So the issue is that this works for entries where the program would only have to forward the mail from one address to the next, but does not work when it has to do this more than once. I realize that the order I enter the Strings into my linked list can also affect whether my program will realize to forward the mail D: I was thinking of placing this for loop inside another for loop so that it runs more times, but I feel like there's a better solution.
Any help would be appreciated!
EDIT: Placing the code inside another for loop DOES work, but I'm curious if there's a better way to do this.