Вопрос

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?

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top