string.contains始终返回true

string.contains始终返回true,string,boolean,contains,String,Boolean,Contains,我制作了一个程序,它接受一个文本文件,将行作为字符串存储在一个数组中。现在我想“过滤”数组中的那些条目 我使用string.contains查看每个数组条目是否都有子字符串“05/Aug” 出于某种原因,它总是返回真值,而事实上,它不应该返回真值 文件如下: 这是我的代码: for (int i=0; i<10;i++) { boolean check = storestrings[i].contains("05/Aug"); if(check =

我制作了一个程序,它接受一个文本文件,将行作为字符串存储在一个数组中。现在我想“过滤”数组中的那些条目

我使用string.contains查看每个数组条目是否都有子字符串“05/Aug”

出于某种原因,它总是返回真值,而事实上,它不应该返回真值

文件如下:

这是我的代码:

for (int i=0; i<10;i++)
    {
        boolean check = storestrings[i].contains("05/Aug");
        if(check = true){
            teststring[i] = storestrings[i];
            //System.out.print(storestrings[i]);
        }
        else{
            teststring[i] = null;

            }

    }

for(int i=0;i您在if语句中使用了赋值运算符而不是等式。它应该是这样的:

if(check == true){
    teststring[i] = storestrings[i];
    //System.out.print(storestrings[i]);
}
或者干脆

if (check) {
    teststring[i] = storestrings[i];
    //System.out.print(storestrings[i]);
}
在代码中,当if语句中达到check=true时,它会将true赋值给check变量并返回true,因此if条件的计算结果总是true