Junior — Middle
How is the performance of searching for an element in an ArrayList evaluated?
sobes.tech AI
Answer from AI
In ArrayList, searching for an element by value (for example, using the contains or indexOf method) is performed by sequentially iterating through the elements from start to end. This means that in the worst case, the search time is O(n), where n is the number of elements in the list. This approach is due to the fact that ArrayList does not store elements in a sorted manner and does not use hashing for searching. However, if the index is known, access to the element occurs in O(1).