This post originated from an RSS feed registered with Java Buzz
by instanceof java.
Original Post: Arrays in java
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Array is referenced data type used to store multiple values of same type in continues memory locations with single variable name.
The size of array can not change at the run time.
Once the memory has been allocated for an array that memory can not be altered at the run time.
Java arrays are objects.
Need of array:
In projects array is used to collect similar type of objects to send all those values with single call.
Problem of primitive data types:
Using primitive data types we can not store values in continuous memory locations.
Due to this limitation we have two problems.
1.we cant store multiple values:
If we want to store multiple values , say 1 to 10 , we must create 10 variables .
All those 10 variables are created at different locations.
2. we can not pass multiple values in single call:
Using primitive variables we can not pass all values to the remote computer with single network call , which increases burden on network and also increase lines of code in program.
Solution:
To solve above two problems , values must be stored in continuous memory locations with single variable name.
This can be possible using array.
In java array is reference data type . it is used to store fixed number of multiple values of same type in continuous memory locations.
Like other data types array is not a keyword it is a concept. it creates continuous memory locations using other primitive or reference types.
Array Limitation:
Array size is fixed , means we can not increase or decrease its size after its creation.