java - What Collection to use when searching and sorting -
there many posts regarding searching collection on stackoverflow. there many posts regarding sorting collection here. looking solution (data structure) handles both. maps great searching (i.e. map.containskey(key), map.get(key)). arraylists great sorting (using simple comparator). program adds elements hashmap (checking dupes .containskey(key)). map values assigned arraylist. simple (one line of code), yet terribly inefficient. uses twice memory.
the program calls unique elements, duplicate elements? have scanned javadocs , see there many collection types whatever flavor need (map, list, table, set, tree, vector, priorityqueue-whatever is). there 1 java collection handles searching , sorting, including duplicate elements?
have considered treemap
?
the map sorted according natural ordering of keys, or
comparator
provided @ map creation time, depending on constructor used.
Comments
Post a Comment