Question

I want to store a list of (Object, int) in a data structure such that the int field can be easily sorted (ascending or descending). I'm looking at Hashtables and TreeMaps but i'm unsure which, if either, of these are good for this purpose. The priority is the sort speed. Any suggestions?

Was it helpful?

Solution

Given what you've told us, it's hard to say what'd be best.

If you're concerned with sorting performance alone, a HashTable or TreeMap (actually a red-black binary tree) have great sorting performance, but they're slower than some other data structures when adding (and in TreeMap's case, deleting) items.

You should probably provide more details regarding what you're doing with the data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top