没有这种方法。把数组放进ArrayList,建立一个Literator,然后用嵌套for循环跟踪

解决方案 »

  1.   

    直接写,没测过呵呵
    --------------------public int getMaxItem(int[] setItem){
      HashMap hmItem = new HashMap();
      int iMaxItem = setItem[0];
      int iMaxCount = 1;
      for(int i=0;i<setItem.length; i++){
        String item = setItem[i] + "";
        if(hmItem.containsKey(item)){
          int count = Integer.parseInt((String)hmItem.get(item)) + 1;
          hmItem.put(item, count + "");
          if(count>iMaxCount){
           iMaxItem = item;
          }
        }
        else{
          hmItem.put(item, 1 + "");
        }
      }  return iMaxItem;
    }
      

  2.   

    Arrays.binarySearch 
      比较方便
      

  3.   

    public static int getMaxItem(int[] array) {
    HashMap hm = new HashMap();
    int maxItem = 0;
    for(int i =0;i<array.length;i++) {  //遍历数组,并用HashMap处理
    Integer i325 = new Integer(array[i]);
    if(hm.containsKey(i325)) {
    ((Counter)hm.get(i325)).i++;
    }
    else {
    hm.put(i325, new Counter());
    }
    }
    Iterator it334 = hm.keySet().iterator();
    while(it334.hasNext()) {  //找出数组中最大值
    int i338 = ((Counter)hm.get((Integer)it334.next())).i;
    if(i338 > maxItem) {
    maxItem = i338;
    }
    } return maxItem;
    }调用如下:
    int[] arr157 = {1,1,3,2,3,3,5,5,1,5,5,5};
    System.out.println(getMaxItem(arr157));
    结果:5
      

  4.   

    忘了,还用到这个类,不好意思,呵呵
    class Counter {    //用于Map的value
      int i=1;
      public String toString() {
        return i+"";
      }
    }