What is Array?
An array is an indexed collection of fixed number of homogeneous data elements.
- In array we can represent multiple values with a single variable.
- Reusability of the code will be improved.
Limitations of object type arrays:
- Arrays are fixed in size: Once we created an array with some size there is no chance to increase and decrease its size based on our requirement, Hence to use arrays compulsory we should know the size in advance which may or may not possible.
- Arrays can hold only homogeneous data elements.
Student s = new Student; (Correct)
S = new Customer; (Wrong)
Compiler Exception: Incompatible type
But we can resolve this problem by using object arrays.
Object o = new Object;
o = new Student;
o = new Customer;
Arrays Concept is not implemented based on some standard data structure hence readymade method support is not available for every requirement we have to write the code explicitly which is complexity of programming.
|Individual Variable Approach
Huge number of variable
Student  S = new Student;
0 1 2 3 ————————-999
We can represent huge no. of variable by using a single variable
- Array concept is not implemented using any datastructure.
Suppose we want to insert element in some sorting order than who will responsible to write the sorting code programmer
But in collection readymade method support is available for sorting we can use Tree Set (Automatically element will insert in some sorting order)
- Second, If we want to search whether the particular element is present or not. So in arrays we will have to write the searching codes.
But in collection we have one readymade method called contains()
- Fixed in size.
- Homogenous elements
- Underlying DS
- 4 Contains()
TO OVERCOME ALL THESE PROBLEMS WE SHOULD GO FOR COLLECTIONS CONCEPT