java - How to get and compare the value results of a map<Integer, Integer> -


by calling method ,at case countinnumbers, returning results array.

system.out.println(countintinnumbers(array)); 

result:

{1=17, 2=10, 3=16, 4=17, 5=13, 6=22, 7=10, 8=15, 9=16, 10=19, 11=11, 12=15, 13=16, 14=13, 15=19, 16=17, 17=13, 18=21, 19=19, 20=15,} 

i try separate numbers on different table depending total value. example... want display numbers total between 3 , 4 separate table other numbers.

facing problem cause results may notice map since new in java , confused @ point.

anyone can suggest start of?

updated::: countintinnumbers method follows

public static map<integer, integer> countintinnumbers(int[][] mat) {     map<integer, integer> intoccurences = new hashmap<>();     (int[] row : mat) {         (int intinrow : row) {             integer occurences = intoccurences.get(intinrow);             if (occurences == null) { // first occurrence                 intoccurences.put(intinrow, 1);             } else { // increment                 intoccurences.put(intinrow, occurences.intvalue() + 1);             }          }      }     return intoccurences; 

i try separate numbers on different table depending total value. example... want print numbers total between 3 , 4 separate table other numbers.

we not sure asking here if mean want display numbers have total between 2 numbers like:

private void printnumbers(map<integer, integer> intoccurences, int mintotal, int maxtotal){     boolean first = false;     system.out.print("{");     (map.entry<integer, integer> entry : intoccurences.entryset()) {         int total = entry.getvalue();         if (total >= mintotal && total <= maxtotal) {             if (first) {                 first = false;             } else {                 system.out.print(", ");             }             system.out.print(entry.getkey() + "=" + total);         }     }     system.out.print("}"); } 

if taking copying values new map maybe like:

private map<integer, integer> extractnumbers(map<integer, integer> intoccurences,        int mintotal, int maxtotal) {     map<integer, integer> result = new hashmap<>();     (map.entry<integer, integer> entry : intoccurences.entryset()) {         int total = entry.getvalue();         if (total >= mintotal && total <= maxtotal) {             result.put(entry.getkey(), total);         }     }     // not sure if want remove ones original map     return result; } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -