How arrays are declared in Java? Explain with example?



Declaration of Array:
Array in Java may be declared in two forms :
1.       type   arrayname[ ];
2.      type   [ ] arrayname;
After declaring an array, we need to create it in the memory. Java allows us to create arrays using new operator only, as shown below :
Arrayname = new type[size];
Example :
number = new int[5];
average = new float[10];
These lines create necessary memory locations for the arrays number and average and designate them as int and float respectively. Now the variable number refers to an array of 5 integers and average refers to an array of 10 floating point values.

Comments

  1. Very helpful content for anyone starting their Java journey. Along with theory, practical exposure is key—consider
    Top AI powered Core JAVA Online Training in Hyderabad for real-world learning.

    ReplyDelete
  2. Nice explanation of Java topics! For learners aiming to become job-ready, exploring
    Top AI powered Core JAVA Online Training in Hyderabad can provide valuable hands-on experience.

    ReplyDelete

Post a Comment

Popular posts from this blog

Traversing of elements program with algorithm and Flowchart

Write a program to add two number using inline function in C++?