Java Design Pattern
Introduction to Java 10
Introduction to Java 11
Introduction to Java 12

Java Array Introduction

  • • An array is nothing but a variable having capability to contain more than one similar types of data items in linear manner.
  • • Array is also called as linear data structure.
  • • The length of an array is established when the array is created. After creation, its length is fixed.
  • • Each item in an array is called an element, and each element is accessed by its numerical index.
  • • Here array index begins with 0. For example, the 9th element will be accessed at index 8.
  • • Java supports two types of arrays, such as one-dimensional array and multi-dimensional array.
  • • The array taking one subscript([]) is known as one-dimensional array.
  • • The array taking more than one subscript is known as multi-dimensional array.

 

// Java program to illustrate creating an array
// of integers,  puts some values in the array,
// and prints each value to standard output.

class ArraySample {
	public static void main(String[] args) {
	// declares an Array of integers.
	int[] arr;

	// allocating memory for 5 integers.
	arr = new int[5];

	// initialize the first elements of the array
	arr[0] = 10;

	// initialize the second elements of the array
	arr[1] = 20;

	//so on...
	arr[2] = 30;
	arr[3] = 40;
	arr[4] = 50;

	// accessing the elements of the specified array
	for (int i = 0; i < arr.length; i++)
	System.out.println("Element at index " + i +
		" : " + arr[i]);
	}
}

Output

Element at index 0 : 10
Element at index 1 : 20
Element at index 2 : 30
Element at index 3 : 40
Element at index 4 : 50

Limitations:

  • • Array size is fixed.
  • • Containing homogeneous data items.
  • • eadymade methods are not supported.

About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.


We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc






 PreviousNext