中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

網(wǎng)站做自簽發(fā)證書(shū)黃金網(wǎng)站軟件免費(fèi)

網(wǎng)站做自簽發(fā)證書(shū),黃金網(wǎng)站軟件免費(fèi),網(wǎng)站設(shè)計(jì)哪個(gè)好,廊坊網(wǎng)絡(luò)推廣建站今天在偶然之間發(fā)現(xiàn)了一個(gè)bug,原因居然是使用了containsAll()方法,這個(gè)問(wèn)題很簡(jiǎn)單,看以下代碼就能發(fā)現(xiàn)很大的問(wèn)題。 package collection;import java.util.ArrayList; import java.util.List;/*** author heyunlin* version 1.0*/ public cl…

今天在偶然之間發(fā)現(xiàn)了一個(gè)bug,原因居然是使用了containsAll()方法,這個(gè)問(wèn)題很簡(jiǎn)單,看以下代碼就能發(fā)現(xiàn)很大的問(wèn)題。

package collection;import java.util.ArrayList;
import java.util.List;/*** @author heyunlin* @version 1.0*/
public class ListExample {public static void main(String[] args) {List<Integer> list = new ArrayList<>();list.add(2);list.add(3);list.add(3);List<Integer> 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));}}

上面的結(jié)果最后一行打印的是true,因?yàn)閏ontainsAll()方法的作用類(lèi)似于遍歷指定的集合c,通過(guò)contains()比較集合中每個(gè)元素,如果有元素不包含在當(dāng)前的list對(duì)象中,就返回false,否則返回true,為了便于理解,寫(xiě)了以下偽代碼

public interface List<E> extends Collection<E> {public boolean containsAll(Collection<?> c) {for (Object o : c) {if (!this.contains()) {return false;}}return true;}}

因此,文章給出的代碼等價(jià)于

package collection;import java.util.ArrayList;
import java.util.List;/*** @author heyunlin* @version 1.0*/
public class ListExample {public static void main(String[] args) {List<Integer> 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));}}

總結(jié):這篇文章分享了一下項(xiàng)目中遇到的關(guān)于containsAll()方法使用時(shí)應(yīng)該考慮到的問(wèn)題,當(dāng)比較的兩個(gè)list中元素個(gè)數(shù)相同時(shí),可以用equals()方法替代containsAll()方法使用,但是在使用之前需要對(duì)兩個(gè)集合排序(因?yàn)長(zhǎng)ist的源碼里已經(jīng)說(shuō)明了,只有但集合元素的個(gè)數(shù)和順序都一樣才返回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 (e1==null ? e2==null :* 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.risenshineclean.com/news/56550.html

相關(guān)文章:

  • dede怎么做網(wǎng)站日記搜索點(diǎn)擊軟件
  • 一般做網(wǎng)站是用什么程序做的烏魯木齊seo
  • 企業(yè)建設(shè)網(wǎng)站個(gè)人總結(jié)報(bào)告seo網(wǎng)站優(yōu)化多少錢(qián)
  • 平臺(tái)電商網(wǎng)站開(kāi)發(fā)5月疫情最新消息
  • 百度網(wǎng)盟推廣怎么選擇投放網(wǎng)站網(wǎng)絡(luò)推廣引流是做什么的
  • 配音秀做素材網(wǎng)站惠州seo推廣公司
  • 響應(yīng)式門(mén)戶網(wǎng)站站長(zhǎng)推薦黃色
  • 找兼職做酒店網(wǎng)站瀏覽器廣告投放
  • 自我介紹ppt配圖上海搜索引擎優(yōu)化seo
  • 公司品牌推廣方案范文廣西壯族自治區(qū)在線seo關(guān)鍵詞排名優(yōu)化
  • 免費(fèi)做微網(wǎng)站google權(quán)重查詢(xún)
  • 高端網(wǎng)站建設(shè)北京企業(yè)網(wǎng)站營(yíng)銷(xiāo)
  • 哪家微網(wǎng)站建設(shè)網(wǎng)絡(luò)營(yíng)銷(xiāo)優(yōu)化推廣
  • 做網(wǎng)站資訊運(yùn)營(yíng)推廣運(yùn)營(yíng)
  • 網(wǎng)站的會(huì)員功能怎么做推廣普通話手抄報(bào)模板
  • 手機(jī) 網(wǎng)站 微信 源碼微信朋友圈廣告怎么推廣
  • 模仿網(wǎng)站怎么防止侵權(quán)搜狗搜索引擎優(yōu)化論文
  • 做企業(yè)網(wǎng)站注意事項(xiàng)廣告軟文200字
  • htnl5 做的視頻網(wǎng)站萬(wàn)網(wǎng)域名續(xù)費(fèi)
  • 做網(wǎng)站優(yōu)化選阿里巴巴還是百度今日頭條10大新聞
  • 傳奇輔助網(wǎng)站怎么做廣告關(guān)鍵詞有哪些類(lèi)型
  • 南寧微網(wǎng)站制作搜索引擎營(yíng)銷(xiāo)特點(diǎn)是什么
  • 醫(yī)療不可以做網(wǎng)站圖片外鏈工具
  • 河北網(wǎng)站制作多少錢(qián)怎么在網(wǎng)上推廣廣告
  • 三站一體網(wǎng)站公司1688網(wǎng)站
  • 如何優(yōu)化網(wǎng)站圖片大小品牌營(yíng)銷(xiāo)策劃網(wǎng)站
  • 網(wǎng)站欄目頁(yè)面百度快速提交入口
  • 網(wǎng)站建設(shè)費(fèi)用如何做賬務(wù)處理baidu com百度一下
  • 做電影網(wǎng)站要怎么樣的主機(jī)bt磁力種子搜索引擎
  • 做企業(yè)云網(wǎng)站的企業(yè)郵箱一個(gè)新品牌怎樣營(yíng)銷(xiāo)推廣