lee

专注技术,关心民生.

BlogJava 联系 聚合 管理
  2 Posts :: 0 Stories :: 1 Comments :: 0 Trackbacks

class string{
 static String str = new String("yes");
 string(){}
}
public class rtyh {
  public static void main(String[] args){
  string strr = new string();
  String st = new String("yes");
  String str = new String("yes");
  String str1 = "yes";
  String str2 = "yes";
  System.out.println(str1==str2);
  System.out.println(st.equals(str));
  System.out.println(st==str);
  System.out.println(str.equals(strr.str));
  System.out.println(str==strr.str);
   }
 }
结果为 ture
               ture
    ture
    ture
                false
所以,==用来对引用的判断,如果是引用的同一个内存单元则相等,否则不相等.equals()用来对字符串内容的逐一判断.

posted on 2005-12-13 13:19 lee 阅读(839) 评论(1)  编辑  收藏

Feedback

# re: 对两个String类型的比较. 2008-03-05 16:21 jlin
第三个应该是false吧  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: