posts - 110, comments - 101, trackbacks - 0, articles - 7
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理
          List <Integer> list = new ArrayList <Integer>();
          Map 
          <Integer,Integer> map = new HashMap <Integer,Integer>();
          for(Integer i :list){
          map.put(i, map.get(i)
          +1);
          }
          把list集合中的數據 循環放進map中
          如果當前元素已經在map中了 就加1
          第二種方法:

          public class Test2{
            
          public static void main(String [] args) {
            List
          <Integer> myList=Arrays.asList(1,1,2,2,3,3,3,4,4);
            HashSet
          <Integer> hs=new HashSet<Integer>(myList);
            
          for(Integer i:hs){
            System.out.println(i
          +" 在List中存在" + Collections.frequency(myList,i) + "");
            }
            
            }
            
          }




          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 咸丰县| 麻城市| 特克斯县| 巴中市| 上饶市| 大同县| 呈贡县| 卢龙县| 连城县| 钦州市| 芮城县| 威宁| 本溪市| 永济市| 南靖县| 上栗县| 宜兴市| 垣曲县| 大新县| 云安县| 贞丰县| 上林县| 莲花县| 疏附县| 马边| 南安市| 壤塘县| 成安县| 郑州市| 奇台县| 肥城市| 江北区| 肥西县| 江安县| 西乌珠穆沁旗| 连云港市| 临高县| 秭归县| 禄丰县| 贵港市| 南部县|