How to put multiple items to a hashtable

Posted on 2009-12-18
Last Modified: 2013-11-23
I have  object that I need to pass down to service.  At my work they wont allow value objects and I was told to just create a hash map and pass it down.

So for example I have the following data
First Name                Last Name           Mi
Smuck                       Joe                      A
Boone                       Daniel                  C

Now I want to create a hashtable which puts the three related items for each two rows in a hashtable(hashmap)??? Saw the below example but not grasping for mulitple related items.

Hashtable ht = new Hashtable();

 ht.put("One", new Integer(1));    
ht.put("Two", new Integer(2));

Object obj = ht.get("One");    
Question by:TheVeee
    LVL 20

    Expert Comment

    by:Sathish David Kumar N
    add that item in list ...
    put that list in to ur HashTable
    LVL 6

    Accepted Solution

    for that matter group you "multiple items" in any object then put that in the map. in this example I use String array:

    Map<String,String[]> multiMap = new HashMap<String,String[]>();

    multiMap.put("Names",new String[] { "Betty", "Hai", "Knut" } ) ;
    multiMap.put("Numbers", new String[] { "Three", "Two", "Fourteen"} ) ;
    LVL 37

    Expert Comment

    >> I want to create a hashtable which puts the three related items for each two rows in a hashtable(hashmap)???
    A map contains key-value pairs.
    I understand that the value shoud be an object that contains the first, last and middel names.
    But what should be the key?

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Suggested Solutions

    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
    Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
    This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now