Array in Java (F)
Array in Java (F)
java provides a data structure, the array, which stores a fixed-size sequential collection of
elements of the same type. An array is used to store a collection of data, but it is often more
useful to think of an array as a collection of variables of the same type.
Instead of declaring individual variables, such as number0, number1, ..., and number99, you
declare one array variable such as numbers and use numbers[0], numbers[1], and ...,
numbers[99] to represent individual variables.
Definition of Array
An array is a group of similar (like-typed) variables that are referred to by a common name. A
specific element in an array is accessed by its index (subscript).
IMP. NOTES
To declare an array we need primitive data type keywords (int, char, double …. )
Arrays of any type can be created & may have one or more dimensions.
This is simplest form of an array & It is also known as one dimensional array.
Example :
MORE EXAMPLES
char p[ ] =new char [10 ] ;
By this a character array called p is created / declared with 10 cells
String s[ ] = new String [15];
By this a String array called s is created / declared to store 15 strings
Find the output
class array
{
Public void main()
{
int id ,x =10;
Initialization of array
Another way(important)
Advantages of arrays: