Reputation: 29
Is there any specific API which needs to be used? Could someone please post how it could be implemented.
Any suggestion would be deeply appreciated.
Upvotes: 1
Views: 7055
Reputation: 7854
Without any further information of contexts and frequent operations, it seems best to use simple string array or embedded java DB.
Upvotes: 1
Reputation: 41240
This will depend upon your requirement which collection would be suitable, If it is list of String then use java.util.List
or if it is set of String then use java.util.Set
or it is also key-value pair then use Map
.
And implementation of each interface also specific to requirement.
When you are talking about data amount then it comes with two things:
Talking on performance if it is ArrayList - The add operation runs in amortized constant time, that is, adding n elements requires O(n)
time. All of the other operations run in linear time (roughly speaking).The constant factor is low compared to that for the LinkedList
implementation.
In case of HashSet
it also offers constant time performance for the basic operations (add, remove, contains and size
), assuming the hash function disperses the elements properly among the buckets.
HashMap
provides constant-time performance O(1)
for the basic operations (get and put
).
And Talking on memory if large collection goes run out of memory that means if you get OutOfMemoryExcaption
. Then you must increase you heap space by passing -Xmxn
.
-Xmxn
Specify the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is 64MB. The upper limit for this value will be approximately 4000m on Solaris 7 and Solaris 8 SPARC platforms and 2000m on Solaris 2.6 and x86 platforms, minus overhead amounts. like -Xmx2048m
Upvotes: 5