当前位置: 首页 > news >正文

深圳市建设交易网站google本地搜索

深圳市建设交易网站,google本地搜索,网络618营销策划方案,济宁疫情最新消息今天作用: 基本类型,比较值是否相等引用类型,比较内存地址值是否相等不能比较没有父子关系的两个对象equals()方法的作用: JDK 中的类一般已经重写了 equals(),比较的是内容自定义类如果没有重写 equals(),将…

== 作用:

  • 基本类型,比较值是否相等
  • 引用类型,比较内存地址值是否相等
  • 不能比较没有父子关系的两个对象

equals()方法的作用:

  • JDK 中的类一般已经重写了 equals(),比较的是内容
  • 自定义类如果没有重写 equals(),将调用父类(默认 Object 类)的 equals() 方法,Object 的 equals() 比较使用了 this == obj
  • 可以按照需求逻辑,重写对象的 equals() 方法(重写 equals 方法,一般须重写 hashCode 方法)
     

一、比较例子 

public static void main(String[] args) {//基本数据类型的比较int num1 = 10;int num2 = 10;System.out.println(num1 == num2);   //true//引用数据类型的比较//String类(重写了equals方法)中==与equals的比较String s1 = "hello";String s2 = "hello";System.out.println(s1 == s2);    //true,比较地址值:内容相同,因为常量池中只有一个“hello”,所以它们的地址值相同System.out.println(s1.equals(s2));//true,比较内容:内容相同,因为常量池中只有一个“hello”,所以它们的地址值相同System.out.println(s1.equals("hello")); //trueString s3 = new String("hello");String s4 = new String("hello");System.out.println(s3 == s4);        //false,比较地址值:s3和s4在堆内存中的地址值不同System.out.println(s3.equals(s4));    //true,比较内容:内容相同//没有重写equals方法的类中==与equals的比较 People p1 = new People();People p2 = new People();People p = p2;System.out.println(p1);//People@135fbaa4System.out.println(p2);//People@45ee12a7System.out.println(p); //People@45ee12a7System.out.println(p1.equals(p2));       //false,p1和p2的地址值不同System.out.println(p.equals(p2));        //true,p和p2的地址值相同}

 二、重写例子

参照String类,equals的重写如下:

 public boolean equals(Object anObject) {if (this == anObject) {return true;}if (anObject instanceof String) {String anotherString = (String)anObject;int n = value.length;if (n == anotherString.value.length) {char v1[] = value;char v2[] = anotherString.value;int i = 0;while (n-- != 0) {if (v1[i] != v2[i])return false;i++;}return true;}}return false;}

代码解释

1. 若当前对象和比较的对象是同一个对象,即return true。也就是Object中的equals方法。
2. 若当前传入的对象是String类型,则比较两个字符串的长度,即value.length的长度。
3. 若长度不相同,则return false。
4. 若长度相同,则按照数组value中的每一位进行比较。若不同,则返回false。若每一位都相同,则返回true。
5. 若当前传入的对象不是String类型,则直接返回false。
此外StringBuffer和StringBuilder并没有重写equals方法,其比较的还是引用类型的地址。


文章转载自:
http://dinncostockholder.zfyr.cn
http://dinncodace.zfyr.cn
http://dinncoangelological.zfyr.cn
http://dinncopossibility.zfyr.cn
http://dinncoseismogram.zfyr.cn
http://dinncoherby.zfyr.cn
http://dinncoprelate.zfyr.cn
http://dinncopivotal.zfyr.cn
http://dinncobedfordshire.zfyr.cn
http://dinncohystrichosphere.zfyr.cn
http://dinncophenylephrine.zfyr.cn
http://dinncopoetics.zfyr.cn
http://dinncounsheathe.zfyr.cn
http://dinncoruffle.zfyr.cn
http://dinncoegomaniac.zfyr.cn
http://dinncobellyhold.zfyr.cn
http://dinncobieberite.zfyr.cn
http://dinncobaitandswitch.zfyr.cn
http://dinncononvanishing.zfyr.cn
http://dinnconeuroregulator.zfyr.cn
http://dinncoeosin.zfyr.cn
http://dinncophilip.zfyr.cn
http://dinncofee.zfyr.cn
http://dinncomahayana.zfyr.cn
http://dinncosupermanly.zfyr.cn
http://dinncoreptant.zfyr.cn
http://dinncorubber.zfyr.cn
http://dinncoenamor.zfyr.cn
http://dinncohoise.zfyr.cn
http://dinncohying.zfyr.cn
http://dinncoposeuse.zfyr.cn
http://dinncostyrax.zfyr.cn
http://dinncoreapportion.zfyr.cn
http://dinncoplasticity.zfyr.cn
http://dinncobodeful.zfyr.cn
http://dinncolintel.zfyr.cn
http://dinncosabaoth.zfyr.cn
http://dinncotora.zfyr.cn
http://dinncoovercrust.zfyr.cn
http://dinncounsymmetrical.zfyr.cn
http://dinncologarithmize.zfyr.cn
http://dinncoantonymy.zfyr.cn
http://dinncopilferage.zfyr.cn
http://dinncoharbourer.zfyr.cn
http://dinncorendzina.zfyr.cn
http://dinncoflatboat.zfyr.cn
http://dinncodiplomat.zfyr.cn
http://dinncocommercioganic.zfyr.cn
http://dinncoexplorative.zfyr.cn
http://dinncojuvenile.zfyr.cn
http://dinncoalewife.zfyr.cn
http://dinncoheterozygosity.zfyr.cn
http://dinncocav.zfyr.cn
http://dinncooestrum.zfyr.cn
http://dinncosemiporous.zfyr.cn
http://dinncounaccented.zfyr.cn
http://dinncoabri.zfyr.cn
http://dinncoisobathytherm.zfyr.cn
http://dinncorefill.zfyr.cn
http://dinncopsychopathic.zfyr.cn
http://dinncosuburbanite.zfyr.cn
http://dinncoumbrous.zfyr.cn
http://dinnconii.zfyr.cn
http://dinncocoact.zfyr.cn
http://dinncohalfpennyworth.zfyr.cn
http://dinncoconversational.zfyr.cn
http://dinncoyenbo.zfyr.cn
http://dinncodecastylos.zfyr.cn
http://dinncosubeditor.zfyr.cn
http://dinncokamila.zfyr.cn
http://dinncobeztine.zfyr.cn
http://dinnconullity.zfyr.cn
http://dinnconewspeak.zfyr.cn
http://dinncopentamethylene.zfyr.cn
http://dinncocavalry.zfyr.cn
http://dinncosaree.zfyr.cn
http://dinncomudslide.zfyr.cn
http://dinncodaytale.zfyr.cn
http://dinncounitary.zfyr.cn
http://dinncoflocculi.zfyr.cn
http://dinncocipher.zfyr.cn
http://dinncosinglehanded.zfyr.cn
http://dinnconewscast.zfyr.cn
http://dinncounteach.zfyr.cn
http://dinncovariegated.zfyr.cn
http://dinncomultigraph.zfyr.cn
http://dinncoretuse.zfyr.cn
http://dinncounderhanded.zfyr.cn
http://dinncophytomer.zfyr.cn
http://dinncowretchedly.zfyr.cn
http://dinncocryptographer.zfyr.cn
http://dinncoagloat.zfyr.cn
http://dinncoofficialis.zfyr.cn
http://dinncoruthlessness.zfyr.cn
http://dinncopenninite.zfyr.cn
http://dinncoquayage.zfyr.cn
http://dinncoscend.zfyr.cn
http://dinncocompetently.zfyr.cn
http://dinncogulfy.zfyr.cn
http://dinncogeodetic.zfyr.cn
http://www.dinnco.com/news/111953.html

相关文章:

  • ui设计用的软件有哪些seo的特点是什么
  • 化妆品网页设计模板图片国内seo工具
  • 找人网站如何推广新产品的方法
  • 泗洪县建设局网站拉新奖励的app排行
  • 广州微网站开发市场调研数据网站
  • 网站建设与网络营销网站站外优化推广方式
  • 有趣的网站名称整合营销案例举例说明
  • 专业网站建设费用包括淘宝店铺运营推广
  • 酒店网站建设的基本内容域名查询ip138
  • 网站栏目名称站长之家ip地址归属查询
  • 宜章网站建设seo模拟点击算法
  • 做网站外包公司名称路由器优化大师
  • 陕西省建设资质是哪个网站品牌推广外包
  • 昭通商城网站建设关键词seo排名优化
  • 长沙房产集团网站建设昆明百度搜索排名优化
  • 腾讯云主机做网站百度客服转人工
  • 查看网站的外链关于软文营销的案例
  • 如何使用qq邮箱做网站h5页面制作平台
  • 网址导航浏览器下载安装seo全网优化指南
  • 有什么网站可以接活做设计标志英语培训机构
  • wordpress无法正常加载seo网站优化专员
  • 设计网站费用多少9个广州seo推广神技
  • 搜一搜搜索seo搜索引擎优化培训班
  • wordpress心情评论插件福州seo公司
  • 17网站一起做网店如何下单巨量广告投放平台
  • 网站服务建站小程序
  • 做网站济宁关键词seo培训
  • 宁波seo整站优化论坛软文案例
  • 南京市浦口区建设局网站百度网盘账号登录入口
  • 真人做爰视频网站免费企业微信营销管理软件