Android 相同的MIME类型字符串在比较操作中不会返回true

Android 相同的MIME类型字符串在比较操作中不会返回true,android,android-contentprovider,android-contacts,Android,Android Contentprovider,Android Contacts,我似乎无法使ContactsContract.CommonDataTypes MIMETYPE常量与我在游标中查询的常量匹配。我已经测试了这两个字符串,它们看起来完全相同,但在条件下比较它们时,不会返回“true” 以下是出现此问题的方法的代码片段: //gets all the information from the cursor and puts into its respective ArrayList for(int i=0; i<C.getCount(); i+

我似乎无法使ContactsContract.CommonDataTypes MIMETYPE常量与我在游标中查询的常量匹配。我已经测试了这两个字符串,它们看起来完全相同,但在条件下比较它们时,不会返回“true”

以下是出现此问题的方法的代码片段:

    //gets all the information from the cursor and puts into its respective ArrayList
    for(int i=0; i<C.getCount(); i++){
        HashMap<String, String> info = new HashMap<String,String>();
        info.put(C.getString(3),C.getString(4));
        Log.d(TAG, "Itertation: "+i);
        Log.d(TAG, "Row Data MIMETYPE: "+C.getString(2));
        Log.d(TAG, "Phone MIMETYPE constant: "+ ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE); //this line and the above line return the exact same string when the data types match
        if(C.getString(2) == ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE){
            Log.d(TAG, "I have entered the phone condition");//does not enter even if they are identical
            phoneNum.add(info);
        }else if(C.getString(2) == ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE){
            Log.d(TAG, "I have entered the Email condition");//does not enter
            emailAddress.add(info);
        }else if(C.getString(2) == ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE){
            Log.d(TAG, "I have entered the Address condition");//does not enter
            postalAddress.add(info);
        }
        C.moveToNext();
    }
我不知道比较结果是否正确。当我检查LogChat以查找应该匹配的迭代时,我得到以下结果:

07-13 17:11:48.764: D/ContactDetail(2904): Itertation: 0
07-13 17:11:48.764: D/ContactDetail(2904): Row Data MIMETYPE: vnd.android.cursor.item/phone_v2
07-13 17:11:48.764: D/ContactDetail(2904): Phone MIMETYPE constant: vnd.android.cursor.item/phone_v2

有人知道为什么这样不行吗?根据我的理解,即使我从CommonDataTypes而不是Data获得常量MIMETYPE(在那里似乎找不到常量。让我知道数据中是否有常量),它应该与我查询的MIMETYPE相同,但可能它们实际上不同。除此之外,我不知道它为什么不起作用。

使用
.equals()
比较字符串。在Java对象上使用
==
比较标识(相同对象)。您需要相等,因此调用
equals()!谢谢你们。
07-13 17:11:48.764: D/ContactDetail(2904): Itertation: 0
07-13 17:11:48.764: D/ContactDetail(2904): Row Data MIMETYPE: vnd.android.cursor.item/phone_v2
07-13 17:11:48.764: D/ContactDetail(2904): Phone MIMETYPE constant: vnd.android.cursor.item/phone_v2