PrabhaT
PrabhaT

Reputation: 888

Best collection to use to store huge data

I need to store huge number of strings in a collection. I dont need a map since I have only the Key. The data size may come upto 4 million or greater. Currently I am using LinkedHashSet. The performance of linkedhashSet is good but it uses hell a lot of memory. I tried LinkedList and it takes too much time.

My requirements are I need to maintain the insertion order. check each item is available in the list/set before throwing a error if its present.

I also tried using comma separated string but it also didnt give much of an improvement.

Could anybody suggest a better solution.

Upvotes: 1

Views: 3051

Answers (2)

Did you try to implemente a TRIE?It maintains the words sorted in alphabetically orders,and it takes less memory ,because you don't maintain separate object for each string.Instead you store just one char in one Node. see https://forums.oracle.com/forums/thread.jspa?messageID=8787521 and http://en.wikipedia.org/wiki/Trie

Upvotes: 1

schippi
schippi

Reputation: 1059

TreeSet is great to maintain order. also be sure you use an appropiate search algorythm to check the Collection for your entry, this can greatly increase your performance!

Upvotes: 1

Related Questions