Understanding Sets, Maps, and Map Methods

Slide Note
Embed
Share

Explore the concepts of sets, maps, and map methods in programming, focusing on efficient operations like adding, removing, and searching for values. Sets allow unique values with no duplicates, while maps hold key-value pairs like a dictionary. Map methods provide functions for manipulating mappings within a map. Dive into understanding these fundamental data structures for efficient data organization and retrieval.


Uploaded on Oct 06, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. 2

  2. Sets (11.2) set: A collection of unique values (no duplicates allowed) that can perform the following operations efficiently: add, remove, search (contains) We don't think of a set as having indexes; we just add things to the set in general and don't worry about order "the" "of" "if" "to" set.contains("to") true "down" "by" "from" "she""you" set.contains("be") false "in" "him" "why" set 3

  3. Maps (11.3) map: Holds a set of key-value pairs, where each key is unique a.k.a. "dictionary", "associative array", "hash" key value "at" 43 map.get("the") key value key value "in" 37 "you" 22 key value key value "why" 14 "me" 31 56 key value "the" 56 set 4

  4. Map methods put(key, value) adds a mapping from the given key to the given value; if the key already exists, replaces its value with the given one returns the value mapped to the given key (null if not found) containsKey(key) returns true if the map contains a mapping for the given key get(key) remove(key) clear() removes any existing mapping for the given key removes all key/value pairs from the map returns the number of key/value pairs in the map returns true if the map's size is 0 returns a string such as "{a=90, d=60, c=70}" size() isEmpty() toString() returns a set of all keys in the map returns a collection of all values in the map adds all key/value pairs from the given map to this map keySet() values() putAll(map) equals(map) returns true if given map has the same mappings as this one 5

  5. Evil Hangman (animation) {ally, beta, cool, deal, else, flew, good, hope, ibex} Guess: e Pattern: - - - - - e - - - e - - - - - - - - - - - - - - - - e - - - e - e - - e - - - e {flew} {flew, ibex} {else} {hope} {ally} {ally, cool} {ally, cool, good} {beta} {beta, deal} {ally, cool, good} Guess: o Pattern: - - - - - - - - - o o - {ally} {cool, good} {cool, good} Pattern: - o o - Guess: d - o o d - o o - {good} {cool} 6

More Related Content