
Map Interface
Introduction In Java, Mapping means storing data in key–value pairs using the Map interface in the Java Collection Framework. A key is used to identify a value. When we provide the key, we can easily retrieve the corresponding value. Example: Key → Student ID Value → Student Name So, when we give the student ID, we can get the student name easily. Map Interface in Java In Java, mapping is implemented using the Map interface. Important Rules Key Duplicate keys are not allowed Value Duplicate values are allowed Example:. Key, Value 101, Kumar 102, Yogesh 103, Hari Null Values Only one null key is allowed (in HashMap) Multiple null values are allowed Common Classes in Map Interface The most commonly used classes are: HashMap LinkedHashMap TreeMap**** HashMap in Java HashMap is the most commonly used class in the Map interface. Syntax HashMap map = new HashMap<>(); Example: import java.util.HashMap; public class Sample { public static void main(String[] args) { HashMap<Integer, String> map
Continue reading on Dev.to
Opens in a new tab




