Author Archives: Stanislav_Panteleev

Java.Collections.WeakHashMap uses WeakReferences. Why not create a SoftHashMap on SoftReferences?

✅ Difference Between WeakReference and SoftReference Feature WeakReference SoftReference GC behavior Collected as soon as no strong refs Collected only when memory is low Lifespan Short Longer (survives longer in memory) Use case Automatic cleanup Memory-sensitive cache So in theory: … Continue reading →

Posted in Без рубрики | Comments Off on Java.Collections.WeakHashMap uses WeakReferences. Why not create a SoftHashMap on SoftReferences?

Java.Collections.Strong references, weak, soft, phantom

This is one of the most fundamental and fascinating topics in Java memory management. Let’s go through all 4 types of references in Java, how the Garbage Collector (GC) treats them, and when you’d use each one.

Posted in Без рубрики | Comments Off on Java.Collections.Strong references, weak, soft, phantom

Java.Collections.What is weak reference ?

In Java, a weak reference is a type of reference that does not prevent an object from being garbage collected. ✅ In plain terms: If an object is only weakly referenced (i.e., no strong references point to it), then the … Continue reading →

Posted in Без рубрики | Comments Off on Java.Collections.What is weak reference ?

Java.Collections.What is the difference between HashMap and WeakHashMap? What is WeakHashMap used for?

Let’s talk about HashMap vs WeakHashMap, and why the second one is super useful in certain cases. 🔍 Main Difference Feature HashMap WeakHashMap Key reference type Strong references Weak references Garbage collection Keys are never GC’d if referenced Keys can … Continue reading →

Posted in Без рубрики | Comments Off on Java.Collections.What is the difference between HashMap and WeakHashMap? What is WeakHashMap used for?

Java.Collections.What is the difference between HashMap and IdentityHashMap? What is IdentityHashMap used for?

Let’s get into the difference between HashMap and IdentityHashMap, and when to use this strange beast of a map. 🎯 TL;DR: ✅ HashMap compares keys using .equals()✅ IdentityHashMap compares keys using == (object reference equality) That’s the core difference — … Continue reading →

Posted in Без рубрики | Comments Off on Java.Collections.What is the difference between HashMap and IdentityHashMap? What is IdentityHashMap used for?

Java.Collections.Why do we need HashMap if we have Hashtable?

🧓 First, a bit of history Hashtable is part of the original Java 1.0. HashMap was introduced in Java 1.2 as part of the new Collections Framework.

Posted in Без рубрики | Comments Off on Java.Collections.Why do we need HashMap if we have Hashtable?

Java.Collections.Stack is considered “obsolete”. What is recommended to replace it? Why?

in modern Java, the Stack class is generally considered obsolete or legacy. Let’s break it down 👇 🛑 Why Stack is considered obsolete 😬 Problems: It extends Vector, which is: A synchronized, thread-safe collection — unnecessary overhead for most use … Continue reading →

Posted in Без рубрики | Comments Off on Java.Collections.Stack is considered “obsolete”. What is recommended to replace it? Why?

Java.Collections.What can PriorityQueue do?

The PriorityQueue in Java is a powerful tool for managing elements based on priority rather than insertion order — super useful in many real-world scenarios like scheduling, simulations, and pathfinding algorithms (like Dijkstra!).

Posted in Без рубрики | Comments Off on Java.Collections.What can PriorityQueue do?

Java.Collections.How to iterate through LinkedList elements in reverse order without using slow get(index)?

🔄 Reversely iterating over a LinkedList without using get(index) is a smart move — because get(i) on a LinkedList is O(n), and doing it in a loop would give you O(n²) total time 😱. ✅ Best way: Use DescendingIterator LinkedList … Continue reading →

Posted in Без рубрики | Comments Off on Java.Collections.How to iterate through LinkedList elements in reverse order without using slow get(index)?

Java.Collections.Is LinkedList singly linked, doubly linked, or quadruple linked?

✅ Java’s LinkedList is Doubly Linked Each node in Java’s LinkedList contains: A reference to the next node A reference to the previous node A value So it’s a classic doubly linked list.

Posted in Без рубрики | Comments Off on Java.Collections.Is LinkedList singly linked, doubly linked, or quadruple linked?