From here I understood that the complexity of some static arr is O(1)
But for dynamic array the size is never set, so how the complexity will be constant? Even Oracle documentation says so.
static int count = 0;
public static void main(String[] args) {
List.of(1, 2, 3, 4, 5).forEach(x -> count++); // Java-10
System.out.println(count);
}
this code should determine the size of the list, if this runs for O(n) times then why
List.of(1, 2, 3, 4, 5).size();
is O(1)