substring 的菜鸟问题

ostrich2fly 2007-02-06 03:02:55
String temp="\tghi";
String temp1=temp.substring(0,0);
String temp2=temp.substring(0,1); //watch是"\t"
System.out.println(temp1.length());//输出是0
System.out.println(temp2.length());//输出1

if (temp1=="")
{
System.out.println("here");
}
else
{
System.out.println("there");//执行这条语句
}

if (temp2=="")
{
System.out.println("Null");
}
else
{
System.out.println("NOt Null");//执行这条语句
}

请问这是为什么啊?谢谢
...全文
101 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
believefym 2007-02-06
  • 打赏
  • 举报
回复
用equals,不要用==
ostrich2fly 2007-02-06
  • 打赏
  • 举报
回复
后面的贴错了

if (temp2=="\t")
{
System.out.println("Null");
}
else
{
System.out.println("NOt Null");//执行这条语句
}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧