MikO
MikO

Reputation: 18741

Java: Fastest structure to store and retrieve large number of strings

I need to create a Java structure to store a large number of String. Then I basically need to add new strings and also check if some string is already present... The order of the strings is not important.

I don't know many Java datatypes but the typical List, Set and Map, so... what would be the fastest datatype for this scenario? May it be a TreeSet or is there any other I'm missing?

Upvotes: 2

Views: 1825

Answers (1)

Jack
Jack

Reputation: 133587

It depends on which kind of access you need.

  • sequential: LinkedList<String>
  • random: ArrayList<String>
  • check for presence: HashSet<String> (this is the one you are looking for according to your reqs)
  • check for presence and sorted traversal: TreeSet<String>

Upvotes: 6

Related Questions