当前位置: 代码迷 >> J2SE >> substring 的初学者有关问题
  详细解决方案

substring 的初学者有关问题

热度:449   发布时间:2016-04-24 17:30:32.0
substring 的菜鸟问题
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 ");//执行这条语句
              }

请问这是为什么啊?谢谢

------解决方案--------------------
用equals,不要用==
  相关解决方案