Iterating a hashtable

folks i have hashtable as
Hashtable <Integer,String>arr = new Hashtable<Integer,String>();
    arr.put(11,"Hello World");
    arr.put(12,"Kamran1");
    arr.put(13,"Kamran2");
    arr.put(14,"Kamran3");
    arr.put(15,"Kamran5");
    arr.put(16,"Kamran6");
    arr.put(17,"Kamran7");
    now i want to get all the elements of the hashtable after key == 14 so if
int mk = 14;
// I want that i should get all the values after 14 .. Is it possible
// I ain't talking about using Enumeration because that iterates through the whole hashtable and i dont want it.. i want iteration after one particular key only ?

Hashtable and HashMap are unordered Maps.
If youwant an ordered Map I suggest TreeMap which is NavigableMap
[http://java.sun.com/javase/6/docs/api/java/util/NavigableMap.html]
The method you can use is tailMap(14) which wil give you a sub map which contains all the entires 14 and after in increasing order.

Similar Messages

  • Iteration over Hashtable howto

    Hi all,
    how can I iterate over a Hashtable object (I need both key and value)?
    Thanks in advance,
    Michele

    Well in that case the below case must solve your requirement.
    Say tmp is the Hashtable which was being returned by that Bean Class method.
    eg: Hashtable tmp=<bean_class>.getHashtableMethod();
    /** This pieace of code Extracts all the keys present in the given Hashtable **/
    Set temp=tmp.keySet();
    Object key[]=temp.toArray();
    /** Now once you have Keys with you extracting value could be done by using Hashtable.get()  method **/
    /** Now the below part displays all the KEY-VALUE pairs avialable in that Hashtable **/
    for(int i=0;i<key.length();i++){
    /** Extracting value specified key get method **/
    Object value=tmp.get( key[i] );
      out.println("KEY :"+key.toString()+",VALUE:"+value.toString());

  • JSP to Java script

    Here is the problem..
    In a JSP page I am generating this dropdown list consisting of person names dynamically from database.
    Now, onSelection of a person name, I want to display the details (i.e the phone number) related to the person in the textbox.
    Any ideas ....?

    In your initial pass to the database retreive all of the detail info along with the names. Store this info in an iterator then a Javascript array:
    <script language="Javascript">
    var[] name;
    var[] adress;
    <%
    while(iterator.hasNext())
    Hashtable record = (Hashtable)iterator.next();
    %>
    name = <%=record.get("Name")%>;
    address = <%=record.get("Address")%>
    %>
    </script>
    Use the Javascript array variables for display in you onSelection function.

  • Simple Hashtable problem - Iteration :-)

    I want to achieve the same effect as this code below, but with a hashtable. By that I mean I would like to itterate through a hashtable, but I'm not quite sure how to do it.
    ArrayList rectangles = new ArrayList();
    for (Rectangle rec : rectangles){
    }Thanks,
    Nate

    I read the API which you should too, and i came up with this big bundle of mess, lol enjoy
    private void doSomething(){
      int[] nums = {1, 2, 3};
      Object[] obs = {new Object(), new Object(), new Object()};
      Hashtable data = new Hashtable();
      for(int i=0; i<nums.length; i++){
        data.put(nums, obs[i]);
    Set k = data.keySet();
    Iterator iter = k.iterator();
    while(iter.hasNext()){
    int key = (Integer)iter.next();
    Object o = data.get(key);
    System.out.println(key + " " + o.toString());

  • How to get iterator values from a managed bean ?

    Due to a bug in selectOneChoice i'm not able to get the label list i want to display directly from an iterator when the value binding is a managed bean.
    To solve the problem i would like to create a managed bean that contains that list and use it as the selectItems to display.
    I would like that the values in that managed bean loaded from the a data control iterator.
    My question is :
    1) is it possible to access the iterator values from a managed bean, i mean without any reference to a page definition
    2) how to do ? is it documented somewhere ? any example ?
    Thank you

    I got it also with this code:
    package view.managedBeans;
    import classification.bean.ClassificationDocument;
    import classification.castor.ClassificationLanguage;
    import java.io.FileNotFoundException;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Hashtable;
    import java.util.List;
    import java.util.Locale;
    import javax.faces.context.FacesContext;
    import javax.faces.el.ValueBinding;
    import javax.faces.model.SelectItem;
    import oracle.adf.model.generic.DCGenericDataControl;
    import org.exolab.castor.xml.MarshalException;
    import org.exolab.castor.xml.ValidationException;
    public class ClassificationLanguageList {
    private java.util.List<SelectItem> supportedLanguages = new ArrayList();
    public ClassificationLanguageList() throws FileNotFoundException,
    MarshalException,
    ValidationException {
    FacesContext ctx = FacesContext.getCurrentInstance();
    ValueBinding vb = ctx.getApplication().createValueBinding("#{data.ClassificationDocumentDataControl}");
    DCGenericDataControl classificationDocumentDataControl = (DCGenericDataControl)vb.getValue(ctx);
    ClassificationDocument classificationDocument = (ClassificationDocument)classificationDocumentDataControl.getDataProvider();
    ClassificationLanguage[] classificationLanguage = classificationDocument.getClassification().getClassificationLanguageList().getClassificationLanguage();
    for (int counter = 1; counter < classificationLanguage.length; counter++) {
    SelectItem language = new SelectItem();
    language.setValue(classificationLanguage[counter].getClassificationLanguageCode());
    language.setLabel(classificationLanguage[counter].getClassificationLanguageLabel());
    supportedLanguages.add(language);
    public void setSupportedLanguages(java.util.List<SelectItem> supportedLanguages) {
    this.supportedLanguages = supportedLanguages;
    public java.util.List<SelectItem> getSupportedLanguages() {
    return supportedLanguages;
    }

  • Problem in Jtree while retrieving values from a hashtable

    Hi
    I am trying to show some values in a Jtree.I am receiving the values in a hashtable.The hashtable contains unique key but duplicate values.i want to show that values of that hashtable in a tree(but unique values)and under each value show all the key of it.can you please tell me how to do that.
    thanks

    If i understand right, you want to do something like this:
                   Hashtable values = yourhashtable;        
              DefaultMutableTreeNode root = new DefaultMutableTreeNode("Values");
              HashMap<Object, DefaultMutableTreeNode> nodes = new HashMap<Object, DefaultMutableTreeNode>();
              Iterator ii = values.keySet().iterator();
              while (ii.hasNext()) {
                   Object key = ii.next();
                   Object value = values.get(key);
                   if (nodes.containsKey(value)) {
                        DefaultMutableTreeNode node = nodes.get(value);
                        DefaultMutableTreeNode child = new DefaultMutableTreeNode(key);
                        node.add(child);
                   } else {
                        DefaultMutableTreeNode node = new DefaultMutableTreeNode(value);
                        DefaultMutableTreeNode child = new DefaultMutableTreeNode(key);
                        node.add(child);
                        nodes.put(value, node);
                        root.add(node);
              JTree tree = new JTree(root);Hope this helps,
    Alex.

  • MissingResourceException when I iterator a collection after closing the PM

    I retrieve a collection, call pm.retrieveAll on it, and then close the PM.
    When I try to iterator over the collection, I get a
    MissingResourceException. I can't figure out why I'm getting the exception,
    if I do a retrieveAll it should retrieve all the fields of all the objects
    in the collection. It's as if there is a rule "Thou shall not iterator over
    a collection after closing the PM". Is this true?
    java.util.MissingResourceException: Can't find resource for bundle
    java.util.PropertyResourceBundle, key resultlist-closed
    at java.util.ResourceBundle.getObject(ResourceBundle.java:314)
    at java.util.ResourceBundle.getString(ResourceBundle.java:274)
    at serp.util.Localizer.get(Localizer.java:270)
    at serp.util.Localizer.get(Localizer.java:121)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.checkClosed(LazyResult
    List.java:349)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.listIterator(LazyResul
    tList.java:403)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.iterator(LazyResultLis
    t.java:397)
    at
    com.verideon.siteguard.services.SchedulerService.getMonitorsToRun(SchedulerS
    ervice.java:103)
    at
    com.verideon.siteguard.services.SchedulerService.schedule(SchedulerService.j
    ava:59)
    at
    com.verideon.siteguard.web.util.TimerServlet$scheduleTask.run(TimerServlet.j
    ava:84)
    at java.util.TimerThread.mainLoop(Timer.java:432)
    at java.util.TimerThread.run(Timer.java:382)
    Here is my code:
    private Collection getMonitorsToRun() {
    Collection c = new LinkedList();
    PersistenceManager pm = null;
    try {
    pm = JDOFactory.getPersistenceManager();
    Extent extent = pm.getExtent(Monitor.class, true);
    String filter = "nextDate <= now";
    Query q = pm.newQuery(extent, filter);
    q.declareParameters("java.util.Date now");
    q.setOrdering("nextDate ascending");
    Hashtable p = new Hashtable();
    p.put("now", new Date());
    c = (Collection) q.executeWithMap(p);
    pm.retrieveAll(c);
    } catch (JDOException e) {
    log.warn("Received JDO Exception while retrieving Monitors " + e);
    } finally {
    pm.close();
    log.debug("Retrieved " + c.size() + " Monitors ready to be ran.");
    Iterator i = c.iterator();
    while (i.hasNext()) {
    Monitor m = (Monitor) i.next();
    log.debug("m id = " + m.getId());
    return c;

    It appears to be a query in which case, yes, a Query result Collection cannot be iterated over.
    The simple way to bypass this is to transfer the results to a non-closing Collection.
    Collection results = (Collection) q.execute ();
    results = new LinkedList (results);
    pm.retrieveAll (results);
    pm.close ();
    On Thu, 27 Feb 2003 14:49:17 +0100, Michael Mattox wrote:
    I retrieve a collection, call pm.retrieveAll on it, and then close the PM.
    When I try to iterator over the collection, I get a
    MissingResourceException. I can't figure out why I'm getting the exception,
    if I do a retrieveAll it should retrieve all the fields of all the objects
    in the collection. It's as if there is a rule "Thou shall not iterator over
    a collection after closing the PM". Is this true?
    java.util.MissingResourceException: Can't find resource for bundle
    java.util.PropertyResourceBundle, key resultlist-closed
    at java.util.ResourceBundle.getObject(ResourceBundle.java:314)
    at java.util.ResourceBundle.getString(ResourceBundle.java:274)
    at serp.util.Localizer.get(Localizer.java:270)
    at serp.util.Localizer.get(Localizer.java:121)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.checkClosed(LazyResult
    List.java:349)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.listIterator(LazyResul
    tList.java:403)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.iterator(LazyResultLis
    t.java:397)
    at
    com.verideon.siteguard.services.SchedulerService.getMonitorsToRun(SchedulerS
    ervice.java:103)
    at
    com.verideon.siteguard.services.SchedulerService.schedule(SchedulerService.j
    ava:59)
    at
    com.verideon.siteguard.web.util.TimerServlet$scheduleTask.run(TimerServlet.j
    ava:84)
    at java.util.TimerThread.mainLoop(Timer.java:432)
    at java.util.TimerThread.run(Timer.java:382)
    Here is my code:
    private Collection getMonitorsToRun() {
    Collection c = new LinkedList();
    PersistenceManager pm = null;
    try {
    pm = JDOFactory.getPersistenceManager();
    Extent extent = pm.getExtent(Monitor.class, true);
    String filter = "nextDate <= now";
    Query q = pm.newQuery(extent, filter);
    q.declareParameters("java.util.Date now");
    q.setOrdering("nextDate ascending");
    Hashtable p = new Hashtable();
    p.put("now", new Date());
    c = (Collection) q.executeWithMap(p);
    pm.retrieveAll(c);
    } catch (JDOException e) {
    log.warn("Received JDO Exception while retrieving Monitors " + e);
    } finally {
    pm.close();
    log.debug("Retrieved " + c.size() + " Monitors ready to be ran.");
    Iterator i = c.iterator();
    while (i.hasNext()) {
    Monitor m = (Monitor) i.next();
    log.debug("m id = " + m.getId());
    return c;
    Stephen Kim
    [email protected]
    SolarMetric, Inc.
    http://www.solarmetric.com

  • Trying to solve the hashtable problem;

    this is a test of a part of my programming, trying to solve the hashtable
    i took out the erronous part and change some of it.i'm trying to print out a table of data with 4 column
    import java.util.*;
    public class test {
         // creating a global hashtable name "b" its
         //static just for the convieniet of it
    static Hashtable b = new Hashtable();
    public static void addItem(String keyid, String t, double p, int q){
    // array size of 4 for my value in hashtable "b"
    String [] array = new String [4];
    // puting all my variables into string array
    //including my keyid as the first in array[0]      
         array[0]=keyid;
         array[1]=t;
         array[2]= String.valueOf(p);//casting of double type to string
         array[3]= String.valueOf(q);//casting of int type to string
         b.put(id,array);//setting key = id and value = my array[]
    public static void main (String args[]) throws Exception {
         String numb = "009", piss="theone";
         double cost = 19.50;
         int a = 1;
         String [] testItem;
         addItem(numb,piss,cost,a); //call of method additem;
         Enumeration e = b.keys();
    // Get all values
    while ( e.hasMoreElements())
    {            tempItem = (String [])e.nextElement(); **// error msg here**
         System.out.println("array element 1"+tempItem[1]);
         System.out.println("array element 2"+tempItem[2]);
         System.out.println("array element 3"+tempItem[3]);
    this is my error msg "ClassCastException: java.lang.String cannot be cast to [Ljava.lang.String;"
    1 =====>cannot find symbol
    symbol  : variable id
    location: class test
            b.put(id,array);//setting key = id and value = my array[]
    2 ===>cannot find symbol
    symbol : variable tempItem
    location: class test
    tempItem = (String [])e.nextElement();
    3 ====>cannot find symbol
    symbol : variable tempItem
    location: class test
    System.out.println("array element 1"+tempItem[1]);
    is there anyway to solve this or anyone can provide me with an alternative way of printing a table with 4 col?

    you should learn to post your code inside code tags
    mangotree wrote:
    1 =====>cannot find symbol
    symbol : variable id
    location: class test
    b.put(id,array);//setting key = id and value = my array[]there is nothing called "id"
    mangotree wrote:
    2 ===>cannot find symbol
    symbol : variable tempItem
    location: class test
    tempItem = (String [])e.nextElement();
    3 ====>cannot find symbol
    symbol : variable tempItem
    location: class test
    System.out.println("array element 1"+tempItem[1]);there is nothing called "tempItem"
    mangotree wrote:
    this is my error msg "ClassCastException: java.lang.String cannot be cast to [Ljava.lang.String;"
    here you are iterating through the keys of the hash table ("b.keys()"), and your key is a String, not a String[; perhaps you want the value instead?

  • Java/xml/hashtable-part 2

    Hi, I'm back. I had a question a few days ago using JDOM to read and write XML files with Java, and then creating a hashtable. Someone replied and helped considerably, but as a beginner programmer, I still have a few problems. My XML document is HUGE, with a huge tree and the key and values that i am trying to extract are children of different elements of the tree. Mainly, I am having problems navigating through a tree. Let's say the following is my XML file (mine is much bigger than this but similar problem), and i want the key of the hashtable to be city and the value to be zipcode.
    <?xml version="1.0" ?>
    - <person>
    - <name>
    <firstname>Joe</firstname>
    <lastname>Stevenson</lastname>
    </name>
    - <homeinfo>
    <address street="12345 Jones Lane Avenue" city="Lyndburg" state="Utah" zip="32423" />
    </homeinfo>
    <phone>345-098-2342</phone>
    <email>[email protected]</email>
    <occupation>Secretary</occupation>
    - <workinfo>
    <workname>Senior Citizen's Association</workname>
    <address street="233 Great Street" city="Baltimore" state="Maryland" zip="23421" />
    </workinfo>
    </person>
    So the output i would like to see is: {Lyndburg= 32423, Baltimore=23421}
    Any help would be wonderful! thanks so much!

    As I just wrote, next time please paste your code between code tags exactly like this:
    &#91;code&#93;
    your code
    &#91;/code&#93;
    You may read the [url http://forum.java.sun.com/faq.jsp#format]formatting help for more information.
    Thank you
    I don't know what happened, maybe you didn't copy/paste my code, or made some changes that broke the code. Here is the corrected version of the code you posted:
    import java.io.*;
    import java.util.*;
    import org.jdom.*;
    import org.jdom.input.*;
    import org.jdom.filter.*;
    public class InfoMap {
        public static void main(String[] args) throws Exception {
            new InfoMap().test();
        void test() throws Exception {
            Map map = new HashMap();
            File f = new File("person.xml");
            Document doc = new SAXBuilder().build(f);
            Iterator iterator = doc.getDescendants(new Filter() {
                public boolean matches(Object obj) {
                    if ((obj instanceof Element) && ((Element)obj).getName().equals("person"))
                        return true;
                    else
                        return false;
                } // <-- this was missing
            while (iterator.hasNext()) {
                Element person = (Element)iterator.next();
                Element homeinfo = person.getChild("homeinfo");
                Element address = homeinfo.getChild("address");
                Attribute city = address.getAttribute("city");
                Attribute zip = address.getAttribute("zip");
                map.put(city.getValue(), zip.getValue());
                Element workinfo = person.getChild("workinfo");
                address = workinfo.getChild("address");
                city = address.getAttribute("city");
                zip = address.getAttribute("zip");
                map.put(city.getValue(), zip.getValue());
            System.out.println(map);
        } // <-- this was missing
    } // <-- this was missing

  • Iterator vs Enumeration

    Does anyone know how to produce the equivalent of an Enumeration with the new Collection classes like ArrayList and HashMap?
    My situation is that I've got a collection (ArrayList) inside of my class, and I'd like clients to be able to see what's in this list without being able to change the list (ie Iterator.delete()) Is there any way to disable the Iterator.delete operation?
    The solution I'm going with right now is just to use the old collections (ie Vector and Hashtable) which still have the .elements() method.
    Ps. Is this a bug in Java?

    1. Performance: The docs say that the unmodifiableXXX
    methods put a 'view' on the collection so it cannot
    be modified. My guess (well, if I had to do this,
    this is what I'd do) is that they create a
    lightweight dummy list object to sit between the
    client and the list and to pass on all non-changing
    operations. However this affects space and time.The affect performance and space is generally going to be negligible. I've never run into trouble doing things like this. Also note that creating an immutable Iterator wrapper it extremely quick and easy and could be an option if all you are doing is returning an Iterator.
    2. Safety: If you're going to make a collection
    immutable and disable some of its functionality by
    throwing a RuntimeException, shouldn't there be a way
    to ask "is this collection immutable or not?"
    Otherwise, you have to either just know what it is or
    be extremely paranoid or just allow things to fail
    unexpectedly.Your API should specify this. If someone tries to modify the list, it will become apparent during development, which is what you want. If you need to sometimes return modifiable and sometimes not, then you will need to address this with a more complicated API.

  • NullpointerException in java.util.Hashtable.access$100 ???

    Hi folks.
    I am trying to reconstruct a Hashtable using my own way of serialization/deserialization via Java Reflection. It works fine with most classes, but a reconstructed hashtable is seriously screwed up. After reconstruction, it is passed as an argument to a class that uses the putAll-Method, which causes a NullpointerException.
    The root in the stack trace is java.util.Hashtable.access$100 at line 90 in java.util.Hashtable. Unfortunately, if you check the source of hashtable, you will only find the class header on this line.
    Is it correct, that javac creates access-methods for inner classes? What are they used for?
    Any idea what could cause this?

    The exception happens whenever I try methods like toString, putAll or hashCode on the hashtable. The code of the deserialization is just a bit to complex to post here.
    I have been able to track the problem down to the internal creation of creation of an iterator by the hashtable.
    Here is the stack trace:
    Exception in thread "main" java.lang.NullPointerException
    at java.util.Hashtable.access$100(Hashtable.java:90)
    at java.util.Hashtable$EntrySet.iterator(Hashtable.java:592)
    at java.util.Collections$SynchronizedCollection.iterator(Collections.java:1096)
    at java.util.Hashtable.hashCode(Hashtable.java:728)
    at java.util.Hashtable.get(Hashtable.java:315)
    at mypackage.serializer.XMLSerializer.buildXML(XMLSerializer.java:205)
    at mypackage.serializer.XMLSerializer.buildXML(XMLSerializer.java:178)
    at mypackage.serializer.XMLSerializer.main(XMLSerializer.java:66)

  • EntrySet has private access in java.util.Hashtable

    Hi friends,
    While i try to retrieve the data from the hashtable through a JSP page, i'm getting the error saying "E:\Tomcat 5.0\work\Catalina\localhost\dd\org\apache\jsp\disp_jsp.java:55: entrySet has private access in java.util.Hashtable
    Iterator i = h.entrySet.iterator();
    For your reference the code goes like this,
    <% Hashtable h = (Hashtable) session.getAttribute("hash");
    Iterator i = h.entrySet.iterator();
    while(i.hasNext())
    %>
    <tr><td>
    <% String st = i.next().toString();
    String k[] = st.split("=");     
    out.println(k[0]); %>
    </td><td><%
    out.println(k[1]); %></td></tr><% } %>
    can anyone tell me how to get rid of this error quickly please.. Thanks in advance...
    Regards,
    Prakash.

    Iterator i = h.entrySet.iterator();Iterator i = h.entrySet().iterator();

  • ConcurrentHashMap VS. HashTable

    Hi all,
    I need to use a thread-safe map and am not sure if I can safely use java.util.concurrent.ConcurrentHashMap instead of HashTable w/o external synchronization. The Java docs says:
    "A hash table supporting full concurrency of retrievals and adjustable expected concurrency for updates. This class obeys the same functional specification as Hashtable, and includes versions of methods corresponding to each method of Hashtable.
    *+However, even though all operations are thread-safe, retrieval operations do+ +not+ +entail locking, and there is+ +not+ +any support for locking the entire table in a way that prevents all access. This class is fully interoperable with+ **+Hashtable+** +in programs that rely on its thread safety but not on its synchronization details.+*
    *+Retrieval operations (including+ **+get+**+) generally do not block, so may overlap with update operations (including+ **+put+** +and+ **+remove+**+). Retrievals reflect the results of the most recently+ +completed+ +update operations holding upon their onset. For aggregate operations such as+ **+putAll+** +and+ **+clear+**+, concurrent retrievals may reflect insertion or removal of only some entries. Similarly, Iterators and Enumerations return elements reflecting the state of the hash table at some point at or since the creation of the iterator/enumeration+*.
    They do +not+ throw [ConcurrentModificationException|http://java.sun.com/javase/6/docs/api/java/util/ConcurrentModificationExceptio
    *+However, iterators are designed to be used by only one thread at a time.+*"
    I do use iterators on my map; and it will be used by many threads at the same time; so does that mean I need to externally "synchronize" my map?
    The parts in bold and italic made me not sure about using the ConcurrentHashMap...

    JavaFunda wrote:
    So can anybody give a example where we hashtable can not be replace by ConcusrrentHashMapPersonally, other than Peter's first suggestion, I can't think of a single one. I believe that EJP's post (other than line 3) was aimed at why you might prefer a HashMap ( not Hashtable) over CHM; and he's dead right.
    Winston

  • Reading data from Hashtable in another file

    how do i read the data from Hashtable which is created in another file. The file which creates hashtable is continuously running , and i want to read the content of the hash table into another file. Both the file exist in same machine.
    Help needed.
    Ancitipated Thanks

    Then you mean "class" or "object", not "file". Yes, you see the details of these classes in the source code files, and the compiled classes are kept in files, but programmers don't think of the files, they think of the objects running in the JVM. By calling them "files" you're causing confusion.
    Anyway, multiple threads can access a hashtable, which is synchronized apparently. So that alone shouldn't be a problem. If you have one object adding to a hashtable while another is reading its contents via an iterator, that could cause ConcurrentModificationExceptions.

  • Additional element to existing key/value pair in hashtable

    I didn't see any other forums like this. My program reads in 3 CSV files as hashtables. The first table is compared to second, which is an exclusion list that causes the first to be reduced. The third table is a map that has the same keys as the first table with an extra element containing the correct nomenclature that needs to be associated with the remaining elements of the first table. If that doesn't make any sense I can try to re-explain the problem. I don't think Element.add() does what I need it to, unless I'm missing a key point.
    Thanks!

    Since you want multiple things attached to a single key, you want the key to map to something that can hold multiple things like an array list.
    Here is how I would attach a single Integer of 17 to the string foo and put it in the first map
    HashMap a = new HashMap();
    a.put("foo", (new ArrayList()).add(new Integer(17)));
    //Now I can get it back if I want, like this:
    ArrayList al = (ArrayList) a.get("foo");
    //and I should find that
    al.size() == 1
    //and
    ((Integer) al.get(0)).value == 17
    //If in the second map I have put a different value associated with foo like 19.
    //I would have done the same basic thing
    HashMap b = new HashMap();
    b.put("foo",(new ArrayList()).add(new Integer(19)));
    //Now if I want to merge I iterate through hash table b and add contents to stuff in a.
    Iterator i = b.keySet().iterator();
    while(i.hasNext()){
      String key = (String) i.get(); // this key was in b
      ArrayList bStuff = (ArrayList) b.get(key);
      ArrayList aStuff = (ArrayList) a.get(key); // could be null if key was not in a
      if (aStuff == null) { // key from second table was not in first so create new one in first.
        a.put(key, bStuff)
      } else { // copy all the stuff from b into a
        for(int j = 0; j<bStuff.size(); j++){
          aStuff.add(bStuff.get(j));
    }

Maybe you are looking for

  • Error in post insert trigger

    Hi to all, In a table I have a field id that must be valorized from sequence. It is possible valorize this sequence after the insert ? I have tried to create a trigger like this: CREATE OR REPLACE TRIGGER MYSCHEMA.POST_USERACCOUNTS_INSERT AFTER INSER

  • Unable to print with Adobe Acrobat Pro - latest version 10.1.10

    Hi, I have installed Adobe Acrobat Pro on my mac book air version 10.9.2. but am unable to print. When I print a PDF, it shows up in the printer icon as complete but when I go to the printer, nothing is there? Can someone help?

  • Can't add URLs to "Get Specified URLs"

    Hey. I've been making a 57-step workflow to get, download and rename each of my Google Calendars. This was working fine, but it hit some kind of snag at step 22. On reloading the workflow, I find that Automator has DELETED the content of all of my "G

  • Feature request -- "seamless tones and colors" to content aware move tool

    The Content Aware Move Tool works pretty doggone well, except that differences in brightness or tones in the selection's new position frequently fail to match. For instance, moving a bird from near the top of the frame, where the sky is lighter blue,

  • Convert one string into multiple strings

    i have a column 'name' in which records are like 'shailesh singh negi','vipin kumar singh'...my requirement is to split this column into three columns like 'firstname','middlename','lastname' and string should insert respectively like 'shailesh' in '