I used Collections.frequency in the past and it worked fine, but now I have problems when I use int [].
Basically Collections.frequency requires an array, but my data is in the form int [], so I am converting my list but not getting results. I think my mistake is to convert the list, but not sure how to do it.
Here is 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);
I don't get the error only zero, but I get strange data when I try to list the elements in Arrays.asList(data)
, if I just add the data directly, it wants to convert my list to collections<?>
Any suggestions?
source share