mercredi 23 mars 2016

Searched far and wide - still no solution to If statement error

I am trying to see if a string in my array matches a word. If so, perform the If statement.

Sounds simple as pie but the If statement does not see the string from the array!

The array (temps) contains nothing but "non"s so I know it's something wrong with the If statment.

Here is the snippet of code:

    if ("non".equals(temps.get(3))) {
        System.out.println("Don't know.");
    }

Where temps is the array containing "non"s on different lines.

Here is the full code in case anyone is wondering:

public class Dump {

public static void main(String[] args) throws IOException {
String token1 = "";

//Reads in presidentsUSA.txt.
Scanner inFile1 = new Scanner(new File("presidentsUSA.txt"));

//Splits .txt file via new lines.
inFile1.useDelimiter("\\n");

List<String> temps = new ArrayList<String>();

while (inFile1.hasNext()) {
  token1 = inFile1.next();
  temps.add(token1);
}
inFile1.close();

// Stores each new line into an array called temps.
String[] tempsArray = temps.toArray(new String[0]);

    if ("non".equals(temps.get(3))) {
        System.out.println("Don't know.");
    }

}

}

Any help would be immensely appreciated...I've already spent so much time on this.

Aucun commentaire:

Enregistrer un commentaire