Author Archives: Stanislav_Panteleev

Java.Collections.What is the worst case running time of the contains() method for an element that is in an ArrayList?

🔍 contains() in an ArrayList Just like in LinkedList, the contains() method in ArrayList: Iterates over the internal array from index 0 to size – 1. Uses .equals() to compare each element with the target.

Posted in Без рубрики | Comments Off on Java.Collections.What is the worst case running time of the contains() method for an element that is in an ArrayList?

Java.Collections.What is the worst case running time of the contains() method for an element that is in a LinkedList?

🔍 contains() in a LinkedList What does it do? list.contains(element) checks whether the list contains a specific element. Internally, it: Starts from the head of the linked list. Iterates through each node. Uses .equals() to compare each node’s value with … Continue reading →

Posted in Без рубрики | Comments Off on Java.Collections.What is the worst case running time of the contains() method for an element that is in a LinkedList?

Java.Collections.What is faster ArrayList or LinkedList?

The answer is: it depends on what you’re doing. But generally: 🏎️ ArrayList is faster than LinkedList in most real-world use cases. Let’s break it down by operations:

Posted in Без рубрики | Comments Off on Java.Collections.What is faster ArrayList or LinkedList?

Java.Collections.What is the difference between ArrayList and LinkedList? When is it better to use the former and when is it better to use the latter?

✅ ArrayList Underlying Structure: Dynamic array. Access Time (get/set): O(1) – Direct access via index. Insert/Delete at End: O(1) amortized – Fast unless the array needs to resize. Insert/Delete in Middle/Beginning: O(n) – Requires shifting elements. Memory Usage: Less overhead, … Continue reading →

Posted in Без рубрики | Comments Off on Java.Collections.What is the difference between ArrayList and LinkedList? When is it better to use the former and when is it better to use the latter?

Java.Collections.Why was ArrayList added if Vector already existed?

🕰️ Background: Why ArrayList was added if Vector already existed? ✅ Short Answer: ArrayList was introduced to fix the design limitations and performance issues of Vector.

Posted in Без рубрики | Comments Off on Java.Collections.Why was ArrayList added if Vector already existed?

Java.Collections.What is the difference between ArrayList and Vector?

Feature ArrayList Vector Introduced in JDK 1.2 (Collections Framework) JDK 1.0 (legacy class) Thread-safe? ❌ No (not synchronized) ✅ Yes (synchronized) Performance ✅ Faster (no locking overhead) ❌ Slower (due to synchronization) Growth mechanism Grows by 50% when full Grows … Continue reading →

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

Java.Core.Why ArrayDeque better than Stack ?

🆚 Stack vs ArrayDeque — Why ArrayDeque wins 1. ✅ Performance Feature Stack ArrayDeque Underlying base Vector (synchronized) Resizable array (not synchronized) Thread-safe? Yes (but outdated style) No (but faster in single-threaded use) Performance Slower due to synchronization Faster — … Continue reading →

Posted in Без рубрики | Comments Off on Java.Core.Why ArrayDeque better than Stack ?

Java.Collections.Which collection implements the FILO maintenance discipline?

✅ The Stack is the classic Java collection that implements FILO behavior. Also called LIFO (Last-In-First-Out), meaning: The first element pushed is the last one popped.

Posted in Без рубрики | Comments Off on Java.Collections.Which collection implements the FILO maintenance discipline?

Java.Collections.Which collection implements the FIFO maintenance discipline?

✅ Queue — and its common implementations — are designed to follow the FIFO order. ✅ The Main FIFO Collection in Java: Queue Java’s Queue interface (from java.util) is specifically designed for FIFO behavior, where:

Posted in Без рубрики | Comments Off on Java.Collections.Which collection implements the FIFO maintenance discipline?

Java.Collections.How to avoid ConcurrentModificationException when iterating over a collection?

💥 Why does ConcurrentModificationException happen? It occurs when: You’re iterating over a collection (using an Iterator or for-each loop) And the collection is structurally modified outside the iterator during iteration

Posted in Без рубрики | Comments Off on Java.Collections.How to avoid ConcurrentModificationException when iterating over a collection?