views:

146

answers:

5

I'm not unduly bothered about read/write performance (though obviously as fast as possible is always good), rather I'm looking for a sorted collection implementation that is as memory efficient as possible. Any suggestions?

+3  A: 

Well then just store it in array of exactly the size you need, and sort it. one time work of O(n log n), and each search thereafter is O(log n). You can easily convrted the sorted array to a List with Arrays.asList().

GregS
If you know how many elements you're going to have, you could make an ArrayList without wasting any space, which would be slightly easier to use.
MatrixFrog
+1  A: 

Why not store them as Fibonacci Heaps? They're fast, small, and effective. If that's too complicated you can look at several other types of heap implementations. Many heaps can be stored as an array. This means you only need as much storage space as you have objects in your collection.

wheaties
+1  A: 

The very smallest sorted Collection is an ArrayList; it's not much bigger than the underlying array. The contents are sorted if you call sort() on them.

Carl Smotricz
A: 

A TreeSet has decent memory conservation and for time performance offers O(log n) insert/lookup.

Kristopher Ives
A: 

ImmutableSortedSet from google-collections is the smallest thing I know of to satisfy your requirement ("sorted collection implementation"), but is not modifiable.

Kevin Bourrillion