How to print data of specific element from an array in java?

Java 8Object Oriented ProgrammingProgramming

An array is a data structure/container/object that stores a fixed-size sequential collection of elements of the same type. The size/length of the array is determined at the time of creation.

The position of the elements in the array is called as index or subscript. The first element of the array is stored at the index 0 and, the second element is at the index 1 and so on.

Each element in an array is accessed using an expression which contains the name of the array followed by the index of the required element in square brackets.

You can access an array element using an expression which contains the name of the array followed by the index of the required element in square brackets. To print it simply pass this method to the println() method.

Example

Live Demo

public class PrintingElement {
   public static void main(String args[]){
      int [] myArray = {23, 93, 56, 92, 39};
      System.out.println(myArray[2]);
   }
}

Output

56
raja
Published on 08-Jan-2018 16:55:14
Advertisements