Grouping Anagrams Using Sorted Strings as HashMap Keys
---------------๐๐ LeetCode Problem 49: Group Anagrams ๐๐-------------------
In Java, arrays cannot be used directly as keys in a HashMap because their hashCode() method does not reflect the actual content. It is therefore recommended to use immutable objects such as strings as keys.
Approach 1: Use a Sorted String as the Key
โญ๏ธ Since two ...
Posted on Fri, 18 Sep 2026 16:20:45 +0000 by ckwall
Display Table and Minimum Frogs Algorithm Problems
Display Table
Given an array of orders where each element contains a customer name, table number, and food item, return a display table showing how many of each dish was ordered at each table.
The table should have "Table" as the first column header, followed by alphabetical sorted food item names. Each row represents a table with its ...
Posted on Sun, 06 Sep 2026 16:36:50 +0000 by joebarker99
Java HashMap Implementation and Mechanisms
HashMap Core Characteristics
HashMap implements key-value storage using hash tables, offering non-thread-safe operations. Both keys and values can be null, and entries are unordered. Pre-JDK 1.8, HashMap used array-chaining (linked lists) to resolve collisions. Since JDK 1.8, when bucket chains exceed 8 elements and the array size surpasses 64, ...
Posted on Fri, 04 Sep 2026 16:49:05 +0000 by kwstephenchan
Java Thread-Safe Collections: ConcurrentHashMap vs HashMap in Concurrent Environments
Overview of Java Thread-Safe Classes
Class Type
Characteristics
Description
Legacy Thread-Safe Classes
Uses synchronized for thread safety
Deprecated classes like Stack, Vector, Hashtable
Collections-Decorated Classes
Wrapper classes using synchronized
Thread-safe versions of standard collections
JUC Classes
Uses CAS and multiple loc ...
Posted on Tue, 18 Aug 2026 16:58:00 +0000 by Ali25m
Popular LeetCode Problems and Solutions
Two Sum
Given an array of integers nums and a target value target, find the indices of two numbers that add up to target. Return the indices as a pair.
Solution 1: Brute Force
class Solution {
public int[] twoSum(int[] nums, int target) {
for (int i = 0; i < nums.length; i++) {
for (int j = i + 1; j < nums.lengt ...
Posted on Wed, 05 Aug 2026 16:23:22 +0000 by Banacek
Understanding HashCode: Collision Resolution and Practical Implications in HashMap
What is a Hash Collision?
When discussing hash collisions, we need to understand the fundamental issue: different objects processed through the same hash algorithm produce identical hash values.
Consider HashMap's internal structureโa combination of an array with linked lists. When a key-value pair is inserted, the hash code determines which ar ...
Posted on Wed, 29 Jul 2026 16:18:10 +0000 by jonsjava
Why Override hashCode() When Overriding equals() in Java
The Default Behavior of equals()
In java.lang.Object, the base implementation simply checks reference identity:
public boolean equals(Object obj) {
return (this == obj);
}
Without overriding, two distinct instances are never equal, even if they hold identical field values.
A typical custom implementation compares logical attributes:
class ...
Posted on Tue, 07 Jul 2026 17:32:15 +0000 by erikhillis
Java Collections Framework: Map Interface, Variable Arguments, and Stream API
Map Interface
Overview and Characteristics
The Map interface represents a collection that maps keys to values. Each key can map to at most one value.
interface Map<K,V> where K is the key type and V is the value type
Key characteristics:
Key-value pair structure with one-to-one mapping between keys and values
Keys must be unique within ...
Posted on Sat, 20 Jun 2026 16:51:24 +0000 by Michael
Removing Multiple Elements from Java Maps
Removing Multiple Elements from Java Maps
Java Maps store key-value pairs. There are scenarios where multiple entries must be removed simultaneous, either based on conditions or by specifying keys. This section demonstrates techniques for bulk removal in Java Maps.
Removing a Single Entry
Use the remove method to delete a single entry by its ke ...
Posted on Tue, 19 May 2026 20:32:36 +0000 by davids701124
Understanding HashMap Internals: A Deep Dive into Source Code
HashMap is one of the most frequently used data structures in Java. Understanding its internal implementation helps developers make better decisions about when and how to use it effectively.
Hash Computation and Index Calculation
The quality of hash distribution directly impacts HashMap performance. The implementation applies a subtle but cruci ...
Posted on Sun, 17 May 2026 11:12:11 +0000 by st0rmer