私の配列内の文字列が単語と一致するかどうかを確認しようとしています。その場合は、Ifステートメントを実行します。farとwideを検索しましたが、まだ解決策がありません。文のエラー
音は単純ですが、If文では配列の文字列は表示されません。
配列(temps)には "non"以外のものが含まれていますので、If文で何か問題があることはわかっています。ここ
コードの抜粋である:
タンが異なる行に「非」Sを含む配列であるif ("non".equals(temps.get(3))) {
System.out.println("Don't know.");
}
。
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.");
}
}
}
これは、デバッガで自分自身をファームウェアにすることができるgreateの例です。 – Peter
temps.get(3)とtemps.get(3).length()を印刷してみてください。あなたはそれがあなたが望むものではないことがわかるかもしれません。 temps.get(3).startsWith( "non")を使用すると、それを修正する可能性があります。 – BPS