I have used Collections.frequency in the past and its worked fine but I'm having problems now that I'm using an int[].
Basically Collections.frequency requires a array but my data is in the form of a int[] so I convert my list but am not getting an results. I think my mistake is in the converting of the list but not sure how to do it.
Here's an example of my problem:
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
public class stackexample {
public static void main(String[] args) {
int[] data = new int[] { 5,0, 0, 1};
int occurrences = Collections.frequency(Arrays.asList(data), 0);
System.out.println("occurrences of zero is " + occurrences); //shows 0 but answer should be 2
}
}
I don't get an error just zero but I get weird data when I try to list the items in Arrays.asList(data)
, if I just add data directly, it wants to convert my list into collections<?>
Any suggestions?