算法:查找int数组中重复的数据

来源:互联网 发布:淘宝联盟红包很无耻 编辑:程序博客网 时间:2024/06/08 07:41

算法:查找int数组中重复的数据


import java.util.HashMap;public class Test {public static void main(String[] args) {Integer[] arr = new Integer[]{1,2,2,3,4,5,6,7,8,8,9,9,0,0};HashMap<Integer,Integer> cache = new HashMap<Integer,Integer>();for(Integer i:arr) {if(cache.get(i) != null) {cache.put(i,cache.get(i) + 1);} else {cache.put(i,1);}}for(Integer i:cache.keySet()) {System.out.println(i + "出现的次数" + cache.get(i));}}}


0 0