Browse by Topic

Popular

Latest

Latest Java Posts

Illustration of an ArrayList with elements being traversed by a foreach loop arrow, showing a cursor moving through the list.
Java

Java ArrayList foreach: Syntax, Pitfalls, and Performance

Learn how to iterate over a Java ArrayList with the foreach loop, including iterator behavior, safe removal, performance tradeoffs, and stream alternatives.

JavaArrayListforeachEnhanced For Loop
Illustration of an empty ArrayList container with the isEmpty method returning true in Java
Java

Java ArrayList isEmpty(): Checking for Empty Lists

Learn how to use ArrayList.isEmpty() in Java to check whether a list contains elements, including internal behavior, null handling, and performance.

JavaArrayListCollectionsisEmpty
Diagram showing an ArrayList with elements and the size() method returning the count
Java

Java ArrayList size: Using size() Correctly

Learn how to get the number of elements in a Java ArrayList with size(), why it is O(1), and how it differs from array length and ArrayList capacity.

ArrayListJava Collectionssize() methodJava List
Illustration of a magnifying glass scanning an ArrayList from the bottom to find the last matching element.
Java

Java ArrayList.lastIndexOf(): Syntax and Behavior

Learn how to use ArrayList.lastIndexOf() to find the last occurrence of an element in a Java list, including null handling, return values, and O(n) linear scan behavior.

ArrayListJava CollectionsList APIIndex Lookup
Illustration of a Java ArrayList with an index marker pointing to a matching element, representing the indexOf search operation.
Java

Java ArrayList indexOf: Finding Element Positions

java arraylist indexof: Learn how to use ArrayList indexOf to find element positions, understand its equals-based search, handle nulls, and avoid performance pitfalls.

ArrayListindexOfJava CollectionsList Search
Illustration of a magnifying glass scanning a list of elements, representing the linear search behavior of ArrayList contains.
Java

Java ArrayList contains: Usage, Performance, and Alternatives

Learn how Java ArrayList.contains works, its linear scan behavior, null handling, and when to switch to HashSet for faster lookups.

ArrayListJava CollectionscontainsHashSet
Illustration of an ArrayList being emptied by the clear() method, showing elements removed while the backing array capacity remains
Java

Java ArrayList clear() Method: Usage and Behavior

Learn how ArrayList.clear() works in Java: its syntax, effect on the backing array, differences from removeAll() and reassignment, and performance and concurrency implications.

JavaArrayListCollectionsMemory Management
Illustration of removing an element from a Java ArrayList, showing elements shifting left to fill the gap.
Java

Java ArrayList remove: Methods, Behavior, and Pitfalls

Learn how to remove elements from a Java ArrayList using index-based and object-based removal, bulk operations, safe iteration, and common pitfalls.

ArrayListJava Collectionsremove methoditeration
Illustration of replacing an element in a Java ArrayList at a specific index using the set method
Java

Java ArrayList set: Replacing Elements at an Index

Learn how to replace an element at a specific index in a Java ArrayList with the set() method, including its return value, bounds checking, and performance.

ArrayListJava Collectionsset methodindex-based access
A Java ArrayList with an index pointer highlighting the get() method retrieving an element from the array-backed list.
Java

Java ArrayList get: Syntax, Performance, and Edge Cases

Learn how to use the get() method of Java's ArrayList: syntax, O(1) performance behavior, bounds checking, and common pitfalls.

ArrayListJava CollectionsList InterfaceIndexOutOfBoundsException