Java Algorithm Patterns: Hash Maps to Array Manipulation

Hash Map Techniques LeetCode 1: Two Sum Utilize a hash map to store elements not yet encountered, while searching for the complement target - nums[i]. public int[] twoSum(int[] nums, int target) { int[] result = new int[2]; Map<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < nums.length; i++) { in ...

Posted on Fri, 08 May 2026 12:03:41 +0000 by SyWill

HashMap Interview Quick Reference and Best Practices

Core Principles (Three Key Points) Underlying Structure HashMap uses an array as the primary storage, combined with linked lists for handling hash collisions, and converts to red-black trees when certain conditions are met. When a linked list exceeds 8 elements and the array length is at least 64, the structure transforms into a red-black tree, ...

Posted on Fri, 08 May 2026 08:50:05 +0000 by dicky18

How ConcurrentHashMap Achieves Thread Safety in JDK 8

Data Structure The internal structure mirrors HashMap, consisting of a hash table array with linked lists for collision handling. When a bucket accumulates more than eight entries, it transforms into a red-black tree for optimized search performance. Implementation Approach JDK 8 leverages synchronized and CAS operations for concurrent access c ...

Posted on Fri, 08 May 2026 01:24:57 +0000 by FRSH