java tutorial - Arrays in Java Example - java programming - learn java - java basics - java for beginners
Java Arrays:
Learn java - java tutorial - Arrays in Java - java examples - java programs
- The array is an object which contains elements of similar data type. It is a data structure where we can store similar elements. We store only fixed set of elements in a java array.
- Array in java is index based; first element of the array is stored at 0 indexes. It is a group of like-typed variables which are referred by one common name. Arrays in Java work differently than they do in C/C++. Following are some important point about Java.
- An array is an ordered list of values
- Array of size N is indexed starts from 0 to N-1.
- A specific value in an array is referenced using the array name and followed by the index in brackets.
Types of Array in java:
There are two types of array.
- Single Dimensional Array
- Multidimensional Array
Single Dimensional Array in java
Syntax
Multidimensional array in java:
Sample Code:
Output:
Advantage of Java Array:
- Code Optimization: It makes the code optimized, we can retrieve or sort the data easily.
- Random access: We can get any data located at any index position.
Disadvantage of Java Array:
- Limited size: We will store only a fixed size of elements in an array. It doesn't grow its size at the runtime. To solve this problem, the collection framework is used in java.