简体   繁体   English

如果在for循环中发出

[英]If issue in for loop

I have a for loop where I want to find an email.I have to strings which are for sure identical. 我有一个for循环,我想在其中找到一封电子邮件。我必须输入肯定相同的字符串。 In the for loop i put a toast and i saw that both show the same thing without any white spaces. 在for循环中,我举杯敬酒,我看到两者都显示相同的东西而没有任何空格。 What I have in if(String == String ) doesn't happen at all. 我所拥有的if(String == String)根本不会发生。 Here is the code : 这是代码:

try {
        jArray = new JSONArray(result);
        JSONObject json_email = null;

        for(int i=0;i<=jArray.length();i++){
            json_email = jArray.getJSONObject(i);

            addedby2 = json_email.getString("email");



        if(addedby2==email2){
            Toast.makeText(this, json_email.toString(), Toast.LENGTH_LONG).show();
            user = json_email.getString("user");
            rpoints = json_email.getString("respectpoints");
            //Toast.makeText(this, user+"    "+rpoints, Toast.LENGTH_LONG).show();
        }
        }
        tvAdded.setText(user + " (" + rpoints + ")");
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

I also tried to getString("user") outside the if condition and it worked. 我还尝试了在if条件之外使用getString(“ user”)并成功。 I tried in if condition to write : String.equals(String) but without any result. 我尝试在if条件下编写:String.equals(String)但没有任何结果。

Does anyone know what the issue could be ? 有人知道这个问题可能是什么吗?

If you are using Java, to compare string values, you have to use the equals() function. 如果使用Java,则要比较字符串值,必须使用equals()函数。 Like Howard said, if that doesn't work, then your variables might be wrong. 就像霍华德所说的那样,如果那不起作用,那么您的变量可能是错误的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM