Things To Remember In Maps (Java)

Keerthivardhan Tekulapelli

Student
Web Developer
Writer
This article helps you to recall the methods and classes of Maps and suggests you some leet code problems that you can start. And this article assumes that you have a basic understanding of the collection framework
K = datatype of Key
V = datatype of Vlaue

Methods To Remember :

put(key , value )
keySet() -> returns Set data structure of all keys
get(key) -> returns value corresponding to the key
containsKey(key) -> true if the key is present else false
isEmpty()
remove(object key) -> removes the key-value pair and returns the value of the argument key
values()
clone() -> returns a shallow copy of the map

Classes To Remember

HashMap
LinkedHashMap: It maintains the insertion order
Data Structures Used: HashTable and LinkedList
TreeMap: It arranges the data in the sorted order considering the keys
Data Structure Used: Red-Black Tree (self-balancing binary search tree)

Methods that we should remember in TreeMap

As TreeMap implements the NavigableMap Interface below are some of the methods which we can invoke with the object of treemap and I feel these are methods that are only mostly used.
firstEntry() -> returns MapEntry<K,V> (the first entry with kay and value which is least among all )
lastEntry() -> returns MapEntry<K , V> (obbesly it will be largest )
pollFirstEntry() -> returns MapEntry<K , V> (removes and returns the first entry )
pollLastEntry() -> returns MapEntry<K , V> (removes and returns the last entry )
subMap(K lowerBound , boolean include , K upperBound , boolean include )
-> returns NavigableMap<K , V >

Exceptions

ClassCastExecption
NullPointerExecption
IllegalArgumentExecption

Problems

Below are a few problems :
Thank you for investing your time in reading this article. I sincerely hope it has provided valuable insights to enhance your journey. If you found it helpful, I encourage you to consider subscribing for more informative content. Feel free to share your insights or any additional information that could contribute to the discussion.
Happy Coding.

Subscribe to my newsletter

Read articles from directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Partner With Keerthivardhan
View Services

More Projects by Keerthivardhan