67.4k views
1 vote
How do you get the value of an element in an array? And how about for an ArrayList?

User ComeIn
by
5.8k points

1 Answer

3 votes

Answer:

array: a[21], b[34] etc.

ArrayList: arr.get(12), arr.get(23)

Step-by-step explanation:

Remember that array is a fixed size collection of values of the same datatypes. We need to provide the array size at the time of the declaration itself. Like:

Student[]=new Student[5];

The above is an array of five student object types.

Similarly, we can have:

a[] =new int[5];

This is an array of five int type.

And we can output the fourth student as Student[4].name, Student[4].marks. And in int case like a[3], a[4], etc.

Similarly, we can get the value from ArrayList as:

arr.get(3);

ArrayList is a resizable array, and can be found inside java.util.ArrayList.

User Angel Fraga Parodi
by
6.3k points