I’m trying to do a arraylist of a hashtable for that i did:
ArrayList<java.util.Hashtable<String, String>> info = new ArrayList<java.util.Hashtable<String, String>>();
this did the job but later i needed to add some hashtables inside info using a for cycle:
java.util.Hashtable<String, String> e = new java.util.Hashtable<String, String>();
while(rs.next()){
e.clear();
for(String a:dados){
e.put(a,rs.getString(a));
}
info.add(e);
}
The problem is that method add doesnt copy e to info, it only define a pointer to e so when i update e all inserted elements gets the new e values.
Can anyone give some help ?
thx for your time.
This should work:
You should try to avoid declaring collections by their implementation class (declare them as
Listinstead ofArrayList, orMapinstead ofHashtable).