java - How to sort a an arraylist of strings by frequency of each element and remove the duplications? -


i hava arraylist of strings

aa,bbb,ccc,ddd,aaa,aaa,aaa,vv,bbb,ggg,....

is there fast possibility sort frequency , delete duplicate elements?

what got create new arraylist, where:

so example above :

aa,1 bbb,2 ccc,1 ddd,1 aaa,3 aaa,3 aaa,3 vv,1 bbb,2 ggg,1 ...

i following:

aaa,3 bbb,2 aa,1 ccc,1 ddd,1 vv,1 ggg,1

my code far:

for (int = 0; i< arr_all_items.size();i++)     {  new_items.add(newitem_in_arr(arr_all_items.get(i).tostring(),collections.frequency(arr_all_items, arr_all_items.get(i).tostring()))); } 

how sort in descending order new_items?

thanks

instead of arraylist, use map object of strings , integers. key string, , object correspond frequency of string. allow 1 of each type, , data want easily.

an alternative create object contains string , frequency, , have comparator based on frequency of object.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -