I would like to know if is it possible to create a vector of hashtables ?
i tried
java.util.Hashtable<String, String>[] info = new java.util.Hashtable<String, String>();
but haven't any luck :(
Thanks.
I think you want
ArrayList<Hashtable<String, String>> info = new ArrayList<Hashtable<String, String>>();
A Vector
is a List
, and a Hashtable
is a Map
, so what you want is a List of Maps.
I'd advise you to use ArrayList
instead of Vector
and HashMap
instead of Hashtable
, respectively (as discussed here and in many other questions), but most of all I'd advise you to change your requirements.
In most cases, you'd want a Map of Lists rather than a List of Maps, and if you do, I'd use one of the many custom implementations available, first and foremost Guava's Multimap
.
You probably want:
ArrayList<Hashtable<String, String>> info =
new ArrayList<Hashtable<String, String>>();
This can be simplified somewhat with type inference and a library such as Guava:
ArrayList<Hashtable<String, String>> info = Lists.newArrayList();
Try to make sure you are using as abstract an interface for the collections you are using as possible.
List<Map<String, String>> info= new ArrayList<Map<String, String>>();
Then you can add your hashtables
Map<String, String> infoElement= null;
for( something in someOtherThing ) {
infoElement= new Hashtable<String, String>();
// add your logic
info.add(infoElement);
}