How to Create Array in Java?

Array is the collection of elements which can be values or variables.

How to Create Array in Java?

Declaration of Array in Java


dataTypeof Array[] arrayName = new dataTypeof Array[Max Size of Array];


Example :

int[] myArray = new int[3];


Initialization of Array in Java

Array can be initialize at same time when it is declare.Here is code :

int [] myArray = {1,2,3,4};


Array can be initialize after its declaration by its index :

myArray[0]=1;

myArray[1]=2;

myArray[2]=3;

myArray[3]=4;




Share this post
  • Share to Facebook
  • Share to Twitter
  • Share to Google+
  • Share to Stumble Upon
  • Share to Evernote
  • Share to Blogger
  • Share to Email
  • Share to Yahoo Messenger
  • More...

0 comments:

Post a Comment