Fabio Fabio - 1 year ago 61
Java Question

Syntax error on token "<", invalid AssignementOperato

I've search all over google but didn't found any fix... Here's the code:

public Command getCommandbyAlias(String alias)
int length;
int i;
for (Iterator localIterator = getCommands().iterator(); localIterator.hasNext(); i < length) //Here, at i < length
Command cmd = (Command)localIterator.next();
String[] alias2;
length = (alias2 = cmd.getAlias()).length;
i = 0;

String aliases = alias2[i];
if (aliases.equalsIgnoreCase(alias)) {
return cmd;
return null;

Answer Source

If you want two conditions in your for statement, you should use the && boolean operator to join them to a single condition:

for (Iterator localIterator = getCommands().iterator(); 
     localIterator.hasNext() && i < length) {

Note, by the way, that you should initialize i and length before you try to use them. You current code does not.