In Java, you can create a map object using the Map
interface and a concrete implementation of the Map
interface, such as HashMap
or TreeMap
.
Here's an example of how to create a HashMap
object in Java:
Map<String, Integer> map = new HashMap<>();
In this example, we're creating a Map
object named map
that maps strings to integers. The Map
interface is parameterized with two types: the type of the keys (String
in this case) and the type of the values (Integer
in this case). The HashMap
class is a concrete implementation of the Map
interface that uses a hash table to store the keys and values.
You can also create a TreeMap
object, which is a concrete implementation of the Map
interface that stores the keys in a sorted order:
Map<String, Integer> map = new TreeMap<>();
You can find more information about the Map
interface and the available implementations in the Java documentation.