java - 2 Hashtable Keys -


i'm having 2 records title.

example
record 1: title
record 2: title

i need store them arraylist using hashtable.

this do.

package com.testing;  import java.util.hashtable; import java.util.arraylist; import java.util.dictionary;    public class anotherclass {     private hashtable <string, string> items = new hashtable <string, string>();     private arraylist <hashtable <string, string>> finalarray = new arraylist <hashtable <string, string>>();      public arraylist <hashtable <string, string>> returnarray() {         return finalarray;     }      public void adding() {             this.items.put("record", "record 1");         this.items.put("format", "my title");         this.finalarray.add(items);              this.items.put("record", "record 2");         this.items.put("format", "my title");         this.finalarray.add(items);     } } 

when print of result of items traversing arraylist shows me 2nd record.

any advice in getting show both records?

thanks!

in between creation of first , second records, put:

this.items = new hashtable <string, string>(); 

the problem you're reusing same hashtable both records.

also, should use hashmap instead of hashtable these days, , should declare variables broadest useful type, here means list rather arraylist, , map rather hashtable or hashmap. there no need describe implementation class in variable's type; it's detail don't need know when using variable, it's clutter.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -