![]() |
In Java, random access in arrays requires direct index-based addressing, it usually takes constant time, or O(1). Standard arrays in Java provide random access that is constant in time. In this article, we will learn how to implement an array with constant-time random access in Java. Constant-Time Random AccessThe term constant-time random access means accessing an element by index takes the same amount of time irrespective of the size of the array.
Program to Implement an Array with Constant-Time Random Access in JavaTo illustrate constant-time random access in arrays, below we have implemented a basic Java program: Java
Output
Element at index 2: 60 Element at index 4: 100 Explanation of the Program:In the above program,
|
Reffered: https://www.geeksforgeeks.org
Java |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |