Accessing Elements and Length Attribute in Arrays || Lesson 53 || Java Programming ||

Publicado em: 23 Julho 2023
no canal de: Wisdomers - Computer Science and Engineering
358
14

Accessing Elements and Length Attribute in Arrays
In this class, We discuss Accessing Elements and Length Attribute in Arrays.
The reader should have prior knowledge of array declaration. Click Here.
Example:
The below diagram shows the code for accessing elements in an array.
class test
{
public static void main()
{
int[] a = {1,2,5,10};
int i;
for(i=0;ilt4;i++)
{
System.out.println(a[i]);
}
}
We use a loop to access elements in an array.
The loop variable “i” is used to point to the index of an array.
a[i] where i = 0,1,2,3.
The below diagram shows the elements in random access memory.
a = 2000 is the starting memory address of the array.
a[0] is 2000 + 0*4 = 2000
The zeroth element is located in 2000 location.
a[1] is 2000 + 1*4 = 2004
The one position element is located in the 2004 position.
In the above way, we find the index location.
For all array objects, we have a length attribute.
The length attribute gives the size of the array.
a.length is 4.

Link for playlists:
   / @wisdomerscse  


Link for our website: https://learningmonkey.in

Follow us on Facebook @   / learningmonkey  

Follow us on Instagram @   / learningmonkey1  

Follow us on Twitter @   / _learningmonkey  

Mail us @ learningmonkey01@gmail.com


Nesta página do site você pode assistir ao vídeo on-line Accessing Elements and Length Attribute in Arrays || Lesson 53 || Java Programming || duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Wisdomers - Computer Science and Engineering 23 Julho 2023, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 358 vezes e gostou 14 espectadores. Boa visualização!