鄙人习惯了php这类的语言,写java未免有点不适应,碰到问题做个总结。
谢谢范哥的指导,范哥在java是行家,还抵得住我骚扰他,他给我发了篇参考:
参考自:http://hi.baidu.com/shashadadao/blog/item/c7cdadde75a5455cccbf1a94.html
原创内容如转载请注明:来自 阿权的书房
Bundle mybundle = intent.getExtras();
String todo = mybundle.getString("todo");
//todo的值是update_list
//if( "update_list" == todo ) 这样不行
//if( "update_list".equals(todo) ) 这样可以
String todo = mybundle.getString("todo");
//todo的值是update_list
//if( "update_list" == todo ) 这样不行
//if( "update_list".equals(todo) ) 这样可以
谢谢范哥的指导,范哥在java是行家,还抵得住我骚扰他,他给我发了篇参考:
引用
在jsp中判断字符串要使用compareTo方法,不要用==,因为在java中String变量不是一个简单的变量而是一个类实例,不同的方法会得到 不同的结果:
1.
结果是"yes"。
2.
结果是"no"。
3.
结果是"no"。
4.
结果是"yes"。
1.
String str1="ABCD";
String str2="ABCD"; (或 String str2="AB"+"CD"; )
if (str1==str2)
out.print("yes");
else
out.print("no");
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");
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");
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");
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
原创内容如转载请注明:来自 阿权的书房
收藏本文到网摘
娱乐八卦一下
电脑是人执行任务的榜样
