msg!="ServerExits!"
用!msg.equal("ServerExits!")
试试看

解决方案 »

  1.   

    估计返回的字符串不只是显示的内容,还有其他你没有看到的东西,你可以试试如下代码:
    while(msg.indexOf("ServerExits!")<0){
       ...
    }
      

  2.   

    String是个类,比较相等应当用String.equal,用==是判断是不是同一个对象
      

  3.   

    对,!=判断的是句柄是否不同,而不是比较实际的值。应该用String.equal()
      

  4.   

    我用过了String.equals()确实可以!但是不明白“==是判断同一个对象"这句话!
    如下:
     String str1="china";
     String str2="china";
     if(str1==str2)
      System.out.println("they are  the same object!");
      else
     System.out.println("they are not the same object!");
    我不知道定义的这两个String对象算不算同一个对象?
    反正结果是they are  the same object!
    顺便问一下"System.out"这是在哪个包下面啊?怎么找不到呢?
      

  5.   

    ==是比较对象,.equals是比较值
    System是在java.lang.System包中
      

  6.   


    while(msg!="ServerExits!")
    改成
    while(msg.equal("ServerExits!"))
      

  7.   

    谢谢大家,但是如下:
    String str1="china";
    String str2="china";              
     if(str1==str2)
      System.out.println("they are  the same object!");
      else
     System.out.println("they are not the same object!");str1应该和str2不是同一个对象吧,可是运行结果是"they are  the same object!"
    这是什么原因呢?把这个问题解决,马上揭帖!再次谢谢大家
      

  8.   

    ==是用来比较常量是否相等或基本类型地变量的值是否相等,而不能比较对象的值,既是比较值而不是比较引用,如果使用!=来比较的话,是无法得出正确的结果地,但是用equals就可以对对象地某项属性或所有属性进行正确的比较
      

  9.   

    可能大家没说过一些传统的面向对象语言。
    如C++中有重载运算符。其实Java本身也运用了这个东东。
    如:String a = "a";
        一个类是不能直接和一个字串相相等的。当出现"="符号时,其实,它运行了String中的一个function ,把"a"赋给String中的一个私有变量。
    String类中,类似的还有:“+”等等。
    在C++中,你可以自己定义这些。