Junior — Middle
What is the time complexity of searching for an element in an ArrayList?
sobes.tech AI
Answer from AI
Searching for an element in an ArrayList takes O(n) time, where n is the number of elements in the list. This is because ArrayList is implemented based on an array, and searching for an element using the contains() or indexOf() method involves sequentially iterating through the elements until a match is found.