public static void main(String[] args) throws IOException{
 BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String st=in.readLine();
    String st1="exit";
    System.out.println(st.length()+" "+st1.length());
   if(st!=st1)
    System.out.println(st+" not equal "+st1);
}显示 exit not equal exit
怎么读入的st="exit"  跟st1不同啊,刚开始学,指导下

解决方案 »

  1.   

    楼主大概想表示的问题2楼已经解答了
    但是关于楼主的问题深层一点的话,
    可能Scanner里面的readLine()返回的是一个new 出来的String,
    所以才会和直接赋值的池中的“exit”不相等有兴趣的可以去看看API源代码
      

  2.   

    补充,关于方法返回值的String的测试: public static void main(String args[]) {
    String str1="abc";
    String str2="abc";
    String str3 = T2.returnStr();
    System.out.println(str1==str2);
    System.out.println(str1==str3);
    }
    public static String returnStr(){
    String str = "abc";
    return str;
    }测试结果:
    true
    true
      

  3.   

    这两个有什么不同吗 str2 str3