鄙人习惯了php这类的语言,写java未免有点不适应,碰到问题做个总结。

Bundle mybundle = intent.getExtras();
String todo = mybundle.getString("todo");
//todo的值是update_list

//if( "update_list" == todo ) 这样不行
//if( "update_list".equals(todo) ) 这样可以


谢谢范哥的指导,范哥在java是行家,还抵得住我骚扰他,他给我发了篇参考:

引用
在jsp中判断字符串要使用compareTo方法,不要用==,因为在java中String变量不是一个简单的变量而是一个类实例,不同的方法会得到 不同的结果:

1.
String str1="ABCD";  
String str2="ABCD"; (或 String str2="AB"+"CD"; )  
if (str1==str2)  
out.print("yes");  
else  
out.print("no");  

结果是"yes"。  


2.  
String str1,str2,str3;  
str1="ABCD";  
str2="AB";  
str3=str2+"CD";  
if (str1==str3)  
out.print("yes");  
else  
out.print("no");  

结果是"no"。  

3.
String str1=new String("ABCD");  
String str2=new String("ABCD");  
if (str1==str2)  
out.print("yes");  
else  
out.print("no");  

结果是"no"。  

4.
String str1=new String("ABCD");  
String str2=new String("ABCD");  
if (str1.compareTo(str2)==0)  
out.print("yes");  
else  
out.print("no");  

结果是"yes"。


参考自:http://hi.baidu.com/shashadadao/blog/item/c7cdadde75a5455cccbf1a94.html


原创内容如转载请注明:来自 阿权的书房
收藏本文到网摘
Tags: ,
发表评论
表情
emotemotemotemotemotemotemotemotemotemotemotemotemot
emotemotemotemotemotemotemotemotemotemotemotemot
打开HTML 打开UBB 打开表情 隐藏
昵称   密码   游客无需密码
网址   电邮   [注册]
               

验证码 不区分大小写
 

阅读推荐

服务器相关推荐

开发相关推荐

应用软件推荐