Count duplicate Integer pairs in an arrayList in java -


"itemprop =" text ">

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. ( i.ic. } {For (J. J. I, J. & LT; size.get (sequence.getId ()); J ++} {// first item get first = sequence.gate items (). Obtain (i); // gets the second item int second = sequence .getItemsets (). Get (j); // Generate Pattern as Pair Couple Pattern = New Couple (First, Second); Serial number = sequence .getId (); // Generate triples with sequence id and pair triples triples = triples (sequence id, i, j); If (! PairList.contains (pattern)) {// say that this pairList.add (pattern) does not exist; }

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:

  (3, 28): 3 (3, 58) ): 1 (It should be removed) (3, 61): 1 extract (5, 21): 2  

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!

pair (pair: list); For (int i = 0; I & lt; pairList.size (); i ++) {for (int j = i + 1; j & lt; pairList.size () - 1; J ++) { If (pairList.get (i) .getX () == pairList.get (j) .getX () and amp; amp; pairList.get (i) .getY () == pairList.get (j) .getY ()) {a ++; System.out.println (pair + ":" + A); }

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

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -