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

做程序的网站长沙网站制造

做程序的网站,长沙网站制造,建设企业网站官网企业网银,豫建设标文件在哪个网站公布今天在偶然之间发现了一个bug#xff0c;原因居然是使用了containsAll()方法#xff0c;这个问题很简单#xff0c;看以下代码就能发现很大的问题。 package collection;import java.util.ArrayList; import java.util.List;/*** author heyunlin* version 1.0*/ public cl…今天在偶然之间发现了一个bug原因居然是使用了containsAll()方法这个问题很简单看以下代码就能发现很大的问题。 package collection;import java.util.ArrayList; import java.util.List;/*** author heyunlin* version 1.0*/ public class ListExample {public static void main(String[] args) {ListInteger list new ArrayList();list.add(2);list.add(3);list.add(3);ListInteger integerList new ArrayList();integerList.add(3);integerList.add(3);integerList.add(3);System.out.println(list);System.out.println(integerList);System.out.println(list.containsAll(integerList));}} 上面的结果最后一行打印的是true因为containsAll()方法的作用类似于遍历指定的集合c通过contains()比较集合中每个元素如果有元素不包含在当前的list对象中就返回false否则返回true为了便于理解写了以下伪代码 public interface ListE extends CollectionE {public boolean containsAll(Collection? c) {for (Object o : c) {if (!this.contains()) {return false;}}return true;}} 因此文章给出的代码等价于 package collection;import java.util.ArrayList; import java.util.List;/*** author heyunlin* version 1.0*/ public class ListExample {public static void main(String[] args) {ListInteger list new ArrayList();list.add(2);list.add(3);list.add(3);System.out.println(list);System.out.println(integerList);System.out.println(list.contains(3));}} 总结这篇文章分享了一下项目中遇到的关于containsAll()方法使用时应该考虑到的问题当比较的两个list中元素个数相同时可以用equals()方法替代containsAll()方法使用但是在使用之前需要对两个集合排序因为List的源码里已经说明了只有但集合元素的个数和顺序都一样才返回true。 /*** Compares the specified object with this list for equality. Returns* true if and only if the specified object is also a list, both* lists have the same size, and all corresponding pairs of elements in* the two lists are equal. (Two elements e1 and* e2 are equal if (e1null ? e2null :* e1.equals(e2)).) In other words, two lists are defined to be* equal if they contain the same elements in the same order. This* definition ensures that the equals method works properly across* different implementations of the List interface.** param o the object to be compared for equality with this list* return true if the specified object is equal to this list*/ boolean equals(Object o); 好了文章就分享到这里了感谢阅读~
http://www.hkea.cn/news/14512749/

相关文章:

  • 建立网站流程图成都市城乡建设厅官方网站
  • 淘宝客网站下载西安知名网站制作公司
  • 商务网站建设实训过程wordpress显示一个分类列表名称
  • 买个网站服务器多少钱wordpress图标居中
  • 深圳场站建设发展有限公司天津seo实战培训
  • 公司网站免费建站怎么样wordpress生成封面分享
  • .net网站开发技术简介wordpress接口
  • 刚做的网站关键词就上来了一级消防工程师考试题库及答案
  • 南京俄语网站建设百度推广的渠道有哪些
  • 国内较好的网站设计公司广西网络电视
  • 做数学题的网站网络推广图片大全
  • 公司网站设计图公司网站如何上传图片
  • 商城网站续费要多少钱网站关键词百度排名在下降
  • 网站开发流程进度规划最新装修设计效果图大全
  • 阿里云服务器做网站好用吗天津网站建设信息科技有限公司
  • 昌邑做网站网站改版协议
  • 哪里可以做网站的wordpress如何添加前台登录
  • 重庆网站自己推广承德网站开发区地税
  • 遵义网站开发的公司有哪些网站你懂我意思正能量免费软件
  • 学做网站论坛 可以吗网站建设海淀区
  • wordpress外贸网站建站教程wordpress内核源码
  • 羊 东莞网站开发百度大全
  • 昆明建网站要多少钱购物网站图片的放大怎么做的
  • 设计网站需要用到哪些技术宁波网站营销推广制作
  • 网站设计深圳要联系方式吗?重庆平台网站建设企业
  • 资讯类响应式网站模板好看的html页面模板
  • 广东建设监理网站网站 验证码错误
  • 绍兴网站制作网站开发者密钥
  • 网站内部链接怎麽做微信h5制作小程序有哪些
  • 学习网页设计与制作的网站网站建设名片