occursMostOften(int[] a) - java
===

im trying to find the number that occurs the most in a given array of int. here is my code, it works but there are some inconsistencies. also, if u can let me know how i can make it better, i think my code is too long!!

    public static int countOccurrences(int[] a, int x) {
		int count = 0;
		for(int i=0;i<a.length;i++) {
			if(a[i] == x) count++;
		}
		return count;
	}
	
	public static int occursMostOften(int[] a) {
		int[] count = new int[a.length];
		boolean[] duplicate = new boolean[a.length];
		for(int i = 0; i < a.length;i++) {
			if(duplicate[i] != true) {
				count[i] = countOccurrences(a,a[i]);
				duplicate[i] = true;
			}
		}
		return a[maxIndex(count)];
	}
	private static int maxIndex(int[] a) {
		int max = 0;
		for(int i = 1; i<a.length;i++) {
			if(a[i-1]<a[i]) max = i;
		}
		return max;		
	}