我匹配兩個java字符串,它匹配大部分相等的字符串,但對於某些值它不匹配,即使字符串是完全相同的。相同的字符串不匹配相同的值
public static Person SearchPersonByID(String id)
{
for(int i=0;i<personList.size();i++)
{
Person p=new Person();
p=personList.get(i);
String useride=p.UserId.toString();
System.out.println(p.UserId+"=="+id);
if(useride.contains(id)||useride.equals(id))
{
System.out.println("Matched");
return p;
}
}return null;
}
我已經調試了程序,雖然值完全相同,但它仍然返回null。 這裏是我想..Kindly值相匹配幫我
ahsan7==ahsan7
它們是相同的,但它返回null
public class Person {
String Status;
String MobileNo;
String Hobbies;
String PersonName;
String Password;
String LastSeen;
String UserId;
String location;
String Adress;
String EmailId;
String Type;
String ImageAdress;
int port;
DefaultListModel<String> FriendsList=new DefaultListModel<>();
Person()
{
}
}
可能重複[我如何在Java中比較字符串?](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – Brian
@staticx注意:這是** not **關於使用'=='比較字符串。請仔細閱讀代碼。 – Jesper
你可以發佈更多的課程嗎? –