vendredi 6 avril 2018

Reading String from CSV file JAVA

So I'm reading from a CSV file and I'm having trouble getting an IF statement to run even though the condition in it is true.

The code I have is the following:

public AbstractAccount CreateAccount(String[] data) {
    String firstname = data[0];
    String lastname = data[1];
    String id = data[2];
    String phonenum = data[3];
    String username = data[4];
    String password = data[5];
    String accounttype = data[6];

    if (accounttype == "Admin")
        return new Admin(firstname, lastname, id, phonenum, username, password);
    else if (accounttype == "CourseCoordinator")
        return new CourseCoordinator(firstname, lastname, id, phonenum, username, password);
    else if (accounttype == "Approver")
        return new Approver(firstname, lastname, id, phonenum, username, password);
    else if (accounttype == "CasualStaff")
        return new CasualStaff(firstname, lastname, id, phonenum, username, password);
    else
        return null;
}

Now I've done some debugging and data[6] is definitely a string that is "Admin" and accounttype is being set correctly, but every time I get to

if(accounttype == "Admin")

the code just jumps over it even though it's true.

Aucun commentaire:

Enregistrer un commentaire