我比較兩個字符串中的if else block..if這是真的如果塊應該執行,如果是假的其他塊應該execute..but我的代碼始終執行其他塊既真&假condition..here是我的代碼我得到錯誤的答案用的if else塊
if(deckey==keystr)
{
.
.
}
else
{
System.out.println("your unauthorised person");
System.exit(0);
}
我deckey是包含字符串值ABC123和keystr我是這裏面也ABC123所獲得的價值(我通過arraylist)
個ArrayList<Integer> listfkey= new ArrayList<Integer>();
String keystr=" ";
for (int i = 0; i < listfkey.size(); i++) {
dech=(char)listfkey.get(i).intValue();
keystr+=dech;
}
請幫我..
比較這樣的字符串將不會很好:你所做的只是比較引用。改用.equals方法。 – Bathsheba 2015-03-13 15:32:27
可能的重複[如何比較Java中的字符串?](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – 2015-03-13 15:33:24
請不要downvote well-posed問題是重複的(除非答案很容易通過搜索獲得)。投票結束。 – Bathsheba 2015-03-13 15:42:10