A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Java Arrays:

Java Arrays

What are Java Arrays ?

Arrays are objects that store multiple variables of the same data type. However, an Array itself is an object on the heap.



We define the variable type with square brackets: like String studentNames[];


Here, we have declared String type Student Name in array

  • An array is a collection of homogenous(similar type) collection of elements which have a contiguous memory location.

  • We can store only a fixed number of elements in an array.

  • It is based on index. Indexing always starts from 0 and goes to length-1.

  • Arrays are used to store multiple values of same datatype in a single variable, instead of declaring separate variables for each value.





Program 1:-
public class ArraysExample
{
 public static void main(String[] args)
 {
  String[] friends = {"Heera", "Navneet", "Sajan", "Sourav"};
  for (int i = 0; i < friends.length; i++)
  {
   System.out.println(friends[i]);
  }
 }
}


 











LEARN TUTORIALS

.

.