Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.HashMap; public class Main { public static boolean getFrequentElementBinary(int[] sample) { HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); ArrayList<Integer> count = new ArrayList<Integer>(); ArrayList<Integer> uniId = new ArrayList<Integer>(); int id = 0; for (int col = 0; col < sample.length; col++) { // System.out.print(bcp[col] + "\t"); int no = 0; if (!map.containsKey(sample[col])) { map.put(sample[col], id++); count.add(1); uniId.add(sample[col]); } else { no = map.get(sample[col]); count.set(no, count.get(no) + 1); } } int maximum = Integer.MIN_VALUE; int maxId = Integer.MIN_VALUE; for (int i = 0; i < count.size(); i++) { // System.out.print(uniId.get(i) + ":" + count.get(i) + ",\t"); if (maximum < count.get(i)) { maximum = count.get(i); maxId = uniId.get(i); } } // System.out.println(); map.clear(); uniId.clear(); count.clear(); if (maxId == 1) return true; else return false; } }