Initiative: To manage associations using Key-Value pairs with the HashMap structure.
import java.util.*; // Import for Map and Entries
public class PhonebookMap { // Define class for associative data mapping
public static void main(String[] args) { // Program entry point
System.out.println("--- Cloud Contact Repository ---"); // Print header
HashMap contacts = new HashMap<>(); // Key: Name, Value: Number
// 1. ADDING PAIRS
contacts.put("Alice", "98765-001"); // Map name Alice to her phone number
contacts.put("Babu", "98765-002"); // Map name Babu to his number
contacts.put("Chitra", "98765-003"); // Map name Chitra to her number
// 2. UPDATING VALUES
contacts.put("Alice", "98765-999"); // Re-mapping Alice; same key overwrites the old number
System.out.println("Updated Phonebook: " + contacts); // Print contents
// 3. RETRIEVAL (GET)
String search = "Babu"; // Key to search for
if (contacts.containsKey(search)) { // Check if the key exists in the map
System.out.println("Found " + search + ": " + contacts.get(search)); // Fetch and print the value
} // End of search check
// 4. REMOVAL
contacts.remove("Chitra"); // Remove the entry associated with key "Chitra"
// 5. FULL ITERATION
System.out.println("\nFull Contact List:"); // Section header
for (Map.Entry entry : contacts.entrySet()) { // Iterate through the entries (pairs)
System.out.println("Name: " + entry.getKey() + " | Phone: " + entry.getValue()); // Print both parts
} // End of entrySet loop
System.out.println("Final Count: " + contacts.size()); // Show total entries remaining
System.out.println("Mapping Lab: Finished."); // Final log for mapping demonstration
} // End of main method
} // End of PhonebookMap class