How to Map a String to a List of Strings in Java.Util.Map

The Java programming language supports various data types that contain collections of data. The simplest, an "array," stores a series of related data values under the same variable name. Other data types are the "map" and the "hash map," which map collections of data to keywords. For example, you can combine an array and a hash map by creating a hash map object containing a series of string arrays and then mapping those arrays to string keywords.

Instructions

    • 1

      Create your basic class as shown in the following example:

      import java.util.HashMap;

      class StringMap{

      public static void main(String[] args){

      }
      }

    • 2

      Declare a HashMap object inside the "main" function:

      Hashmap hm = new Hashmap();

    • 3

      Create two arrays of String objects in the "main" function:

      String[] list = new String[20];
      String[] list2 = new String[20];

    • 4

      Map a String object to the array inside the HashMap object:

      hm.put("Mapped", list);
      hm.put("Mapped2", list2);

Related Searches

References

Related Ads

Check It Out

7 Tips for Photographing Your Kids on Halloween