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.
Very helpful content for anyone starting their Java journey. Along with theory, practical exposure is key—consider
ReplyDeleteTop AI powered Core JAVA Online Training in Hyderabad for real-world learning.
Nice explanation of Java topics! For learners aiming to become job-ready, exploring
ReplyDeleteTop AI powered Core JAVA Online Training in Hyderabad can provide valuable hands-on experience.