Home » Android » android – custom list sorting in Java-Exceptionshub

android – custom list sorting in Java-Exceptionshub

Posted by: admin February 26, 2020 Leave a comment

Questions:

I have a list of this kind.

ArrayList <int> letterVowels = new ArrayList () {0,0,0,0,1,1,1,1,2,2,2,2};

it needs to be sorted so that a list of this type is output.

ArrayList <int> letterVowels = new ArrayList () {0,1,2,0,1,2,0,1,2,0,1,2};

how can I export it so as not to overload the system, surely there is a formula whereby you can do this?

How to&Answers:

How about use the Huffman encoding?

The list data is {0,0,0,0,1,1,1,1,2,2,2,2}.
In this case you can mapping like this {0:4, 1:4, 2:4} by using Map structure.

You can extract keys of the map by using this method keySet()

After that, print value(0, 1, 2) using key.