Lesson 32 of 34

HashMap: Key-Value சேமிப்புHashMap: Key-Value Storage

10 min 35 XP

HashMap ஒவ்வொரு key-க்கும் ஒரு value சேமிக்கும், அகராதி போல. Key மூலம் value-ஐ மிக வேகமாகப் பெறலாம். Key-கள் தனித்துவமானவை; அதே key-க்கு மீண்டும் put செய்தால் பழைய value மாறும்.

A HashMap stores a value for each key, like a dictionary, and finds a value by its key very fast. Keys are unique: putting the same key again replaces its value.

Example: edit me and press Run

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.

சொற்களை எண்ணுவது HashMap-ன் மிகப் பிரபலமான பயன்பாடு: map.put(w, map.getOrDefault(w, 0) + 1). வரிசை முக்கியமெனில் TreeMap (sorted keys) பயன்படுத்துங்கள்.

Counting things is the classic HashMap use: map.put(w, map.getOrDefault(w, 0) + 1). If you need the keys in sorted order, use a TreeMap.

Example: edit me and press Run

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.

Challenge

+35 XP

small letters சொல் ஒன்றைப் படித்து, முதன்முதலில் ஒரு முறை மட்டுமே வரும் எழுத்தை print செய்யுங்கள். அப்படி எதுவும் இல்லையெனில் -1 print செய்யுங்கள். Input: swiss → Output: w

Read a lowercase word and print the first character that appears only once. If there is none, print -1. Input: swiss → Output: w

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.