Nick Nick - 1 year ago 125
Java Question

Multiset in Android

I have a structure

class A
float key;
Foo data;

I need to maintain an array of these structures sorted by
. Insertion and deletion of elements into the array must be efficient (say
O(log n)
is not guaranteed to be unique. Also I need to enumerate the array in the sorted order. Random access by index is not needed.

If I were using C++, I would use

What would you suggest to use for Java for Android?

Answer Source

You can use Guava Multiset in order to achieve what you want. In Android Studio you just need to add the following dependancy to your build.gradle:

compile ''

Then you just need to declare a Multiset of your class, like this:

Multiset<A> multiset = HashMultiset.create();

multiset.add(new A(1.5, "a"));

If you take a look at the docs the available methods should allow you to do what you need.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download