/**数组中元素重复最多的数
* @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}
- public static void main(String[] args) {
- String [] arry = {"1","1","1","1","1","2","2","2","2","2","3","3","3","3",};
- Map<String,Integer> map = new HashMap<String, Integer>();
- for(int i =0 ;i<arry.length;i++){
- if(null!= map.get(arry[i])){
- map.put(arry[i], map.get(arry[i-1])+1);
- }else{
- map.put(arry[i],1);
- }
- }
-
- Iterator it = map.entrySet().iterator();
- while(it.hasNext()){
- Map.Entry entry = (Map.Entry) it.next();
- String key = entry.getKey().toString();
- int value = Integer.parseInt(entry.getValue().toString());
- System.out.println("key is :"+key+"---value :"+value);
- }
- }