欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網!

Java編程

當前位置:主頁 > 軟件編程 > Java編程 >

Java編程中的HashSet和BitSet詳解

來源:本站原創(chuàng)|時間:2020-01-10|欄目:Java編程|點擊: 次

Java編程中的HashSet和BitSet詳解

我在Apache的開發(fā)郵件列表中發(fā)現一件很有趣的事,Apache Commons包的ArrayUtils類的removeElements方法,原先使用的HashSet現在換成了BitSet。

HashSet<Integer> toRemove = new HashSet<Integer>(); 
for (Map.Entry<Character, MutableInt> e : occurrences.entrySet()) { 
  Character v = e.getKey(); 
  int found = 0; 
  for (int i = 0, ct = e.getValue().intValue(); i < ct; i++) { 
    found = indexOf(array, v.charValue(), found); 
    if (found < 0) { 
      break; 
    } 
    toRemove.add(found++); 
  } 
} 
 
 
return (char[]) removeAll((Object)array, extractIndices(toRemove)); 

新代碼如下:

BitSet toRemove = new BitSet(); 
for (Map.Entry<Character, MutableInt> e : occurrences.entrySet()) { 
  Character v = e.getKey(); 
  int found = 0; 
  for (int i = 0, ct = e.getValue().intValue(); i < ct; i++) { 
    found = indexOf(array, v.charValue(), found); 
    if (found < 0) { 
      break; 
    } 
    toRemove.set(found++); 
  } 
} 
return (char[]) removeAll(array, toRemove); 

為什么會使用BitSet代替HashSet呢?

據Apache Commons作者指出,這樣代碼執(zhí)行時可以占用更少的內存,速度也更快。

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

上一篇:Java編程刪除鏈表中重復的節(jié)點問題解決思路及源碼分享

欄    目:Java編程

下一篇:淺談Java編程ToString()方法重寫的意義

本文標題:Java編程中的HashSet和BitSet詳解

本文地址:http://mengdiqiu.com.cn/a1/Javabiancheng/8467.html

網頁制作CMS教程網絡編程軟件編程腳本語言數據庫服務器

如果侵犯了您的權利,請與我們聯系,我們將在24小時內進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網 版權所有