Ask Your Question
1

Can an Array of Elements be made in Android?

asked 2021-11-07 11:00:00 +0000

qstack gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-01-17 02:00:00 +0000

djk gravatar image

Yes, an array of elements can be made in Android. An array is a collection of similar data types that are stored in contiguous memory locations. In Android, arrays can be created for various data types such as integers, strings, characters, etc.

Here is an example of creating an array of integers in Android:

int[] myArray = new int[5]; // creating an array of 5 integers myArray[0] = 10; // assigning value 10 to the first element of the array myArray[1] = 20; // assigning value 20 to the second element of the array myArray[2] = 30; // assigning value 30 to the third element of the array myArray[3] = 40; // assigning value 40 to the fourth element of the array myArray[4] = 50; // assigning value 50 to the fifth element of the array

// Accessing elements of the array int firstElement = myArray[0]; // will return 10 int secondElement = myArray[1]; // will return 20 int thirdElement = myArray[2]; // will return 30 int fourthElement = myArray[3]; // will return 40 int fifthElement = myArray[4]; // will return 50

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-11-07 11:00:00 +0000

Seen: 19 times

Last updated: Jan 17 '23