views:

364

answers:

6

Berkeley DB would be the best choice probably but I can't use it due to licensing issues.

Are there any alternatives?

+2  A: 

Your question could mean one of two things.

If you mean a data structure for storing key-value pairs, use one of the Map instances that are a standard part of the JDK.

If however you are after an in-memory key-value store then I would suggest taking a look at EHCache or even memcached.

cletus
in-memory key-value store
Roman
+2  A: 

HashMap?

Chris Dennett
It lacks transactions management and possibility to keep some data in the disk and another part in-memory and so on.. //sarcasm
Roman
Ah, I see :) There was a problem a while back with someone wanting to develop stuff for Android but needed to use a storage-backed hashmap because the size of his data was too large. Something similar, I guess.
Chris Dennett
A: 

There are lightweigh or embedded dbs like HSQLDB, Derby, SQLite But like others don't understand why you need a db to store key/values...

Why not a Map? Need to keep key/values on app reboot?

Also it's perhaps not what you need but with html5 on up to date browsers you have localStorage that permits you to store key/values in the browser using javascript.

Sebastien Lorber
+1  A: 

jdbm works great for this sort of thing. It's intended for storing on disk in a paged file, provides for basic transaction support (no guarantees on isolation, but ACD are covered). We've used it in a production system with fairly wide deployment and have been quite pleased with the performance, stability, etc...

Kevin Day
A: 

Consider using jredis. It's a Java client for Redis, a persistent key-value store. There's also a JDBC driver for it: code.google.com/p/jdbc-redis/.

Nathan Hurst
A: 

You can try Hazelcast. Just add hazelcast.jar to your classpath. And start coding

java.util.Map map = Hazelcast.getMap("myMap");

You'll get an in-memory, distributed, dynamically scalable data grid which performs super fast.

Fuad Malikov