Java guides
Every published Java guide, newest first, with practical examples you can copy into your own project.
3,965 guides across 14 topics
Topics
Popular Java guides
Most readLatest Java guides
Page 59 of 109Java 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.
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.
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.
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.
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.
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.
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.
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.
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.
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.