java - How to find count of duplicate elements in arraylist and append the dupplicate elements to different textviews -


how find count of duplicate elements in arraylist , append duplicate elements different textviews in andorid.

i have 3 different textview , single arraylist contains 25 elements duplicate elements 1) how many duplicate values present in arraylist 2) count of duplicate values should append textview.

collections.frequency gives occurrences of object in list.

another option since small array sort , iterate, , in case array[i+1] == array[i], increase count of duplicate values.

if elements in case not primitive type, remember overload operator.

sample implementation:

void countocc(int []arr) {       set<integer> uniques = new linkedhashset<integer>();     for(int x : arr) {         uniques.add(x);     }      for(int y : uniques) {         int totalocc = collections.frequency(arrays.aslist(arr), y);         //gives total occurences each unique element in array     } } 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -