Java Collection How to - Create String to Your own type map








Question

We would like to know how to create String to Your own type map.

Answer

import java.util.HashMap;
import java.util.Map;
/*from  www. j  a v a  2 s.c  om*/
public class Main {

  public static void main(String... args) {
    Map<String, MyData> map = new HashMap<String, MyData>();
    map.put("A", new MyData());

    System.out.println(map);
  }
}

class MyData {
  String theString;
  byte[] theBitmap;
  int theInt;
  
}

The code above generates the following result.