Count duplicate Integer pairs in an arrayList in java -
I run into one of the steps I find in duplicates in the list called (PairList) and have an algorithm, Their calculations and pairs, which are smaller than a particular parameter, finish (minSupp). This is to add the pair to my code PairList. ( Now pairs have added something like this in the list: (3, 28) (3, 58) (3, 61) (3, 28) (5, 21) (3, 28) (5, 21) For example, I want to know how many times (3, 28) are in this list. And for (minSupp = 2) I want to delete the pair less than 2 times, so the output should be like this: I worked on it and it is my code so far It gives me a product that is much more than what I want, please help!
(3, 28): 3 (3, 58) ): 1 (It should be removed) (3, 61): 1 extract (5, 21): 2
archive. Frequency ()
is already sufficient If you have implemented pair -class in the equal
then find the frequency of a pair in the list, then your nested for- Loops are redundant, just by removing joints can be done through .remove ()
. If you want each pair to be printed only once, then you can add a list to set and then iterate again (you have hashCode
Will also need to be implemented):
for <> <> (pair pair: new HashSet & lt; pair & gt; (pairList)) // set one double entry frequency is int = Collections .frequency (pairList, pair); System.out.print (pair + ":" + frequency); // The print frequency of the pair (frequency & lt; minSupp) {// If the frequency is too low then remove this pair (pairList.remove (pair)); // Remove all events in this pair System.out.print ("remove"); } System.out.println (); }
Take a look at the hashcode
and equal
this question:
Comments
Post a Comment