Syntax

Java Create a Map Syntax

In Java, create a map: creates key-value pairs — Map<String, Integer> ages = new HashMap<>(); ages.put("Ada", 36);

Quick Answer

Syntax
Map<String, Integer> ages = new HashMap<>(); ages.put("Ada", 36);
JavaSyntax

Create a Map

Code example
Map<String, Integer> ages = new HashMap<>(); ages.put("Ada", 36);

Creates key-value pairs.

Learn More

How to create a map in Java

  1. Open your Java file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Java Create a Map Syntax

Use Map<String, Integer> ages = new HashMap<>(); ages.put("Ada", 36);.

Related Syntax References

Frequently asked questions

What is the Java syntax for create a map?

Use this pattern: Map<String, Integer> ages = new HashMap<>(); ages.put("Ada", 36);

Can I copy this Java code example?

Yes. Use Copy code and adapt the example to your program.

Is this Java syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify