1• An array is a container object that holds a fixed number
2of values of a single type. The length of an array is established
3when the array is created. After creation, its length is fixed.
4You have seen an example of arrays already, in the main
5method of the "Hello World!" application.
6This section discusses arrays in greater detail.
7• Each item in an array is called an element,
8and each element is accessed by its numerical index.
9
10• Advantage of Java Array
11o Code Optimization: It makes the code optimized,
12we can retrieve or sort the data easily.
13o Random access: We can get any data located at any index position.
14• Disadvantage of Java Array
15o Size Limit: We can store only fixed size of elements in the array.
16It doesn't grow its size at runtime. To solve this
17problem, collection framework is used in java.
1 // *** An array is a collection of data items, all of the same type,
2 // accessed using a common name
3
4int main()
5{
6
7 // Creating an integer array named arr of size 10.
8 int arr[10];
9 // accessing element at 0 index and setting its value
10 // to 5.
11 arr[0] = 5;
12 // access and print value at 0 index we get the output
13 // as 5.
14 printf("%d", arr[0]);
15
16 return 0;
17}