Java实现找出数组中重复次数最多的元素以及个数

时间:2021-05-22 21:29:11
/**数组中元素重复最多的数
* @param array
* @author shaobn
* @param array
*/
public static void getMethod_4(int[] array){
Map<Integer, Integer> map = new HashMap<>();
int count = 0;
int count_2 = 0;
int temp = 0;
for(int i=0;i<array.length;i=i+count){
if(i==array.length-1){
temp =1;
break;
}
for(int j=i+1;j<array.length;j++){
if(array[i]==array[j]){
count++;
}
continue;
}
if(count>count_2){
count_2 = count;
map.put(count_2, array[i]);
} }
System.out.println(map.get(count_2));
} int[] array = {1,1,1,5,5,8,9}