Arrays Collections
1. Arrays r fixed in size and hence once we created an array we are not allowed to increase or decrease the size based on our requirement.
Collections are growable in nature and hence based on our requirement we can increase or decrease the size.
2. Memory point of view arrays are not recommended to use.
Memory point of view collections are recommended to use.
3. Performance point of view arrays are recommended to use.(Faster)
Performance point of view collections are not recommended to use.
4. Arrays can hold only homogeneous elements.
Collections can hold both homogeneous and heterogeneous elements.
5. Arrays can hold both primitives as well as objects.
Collections can hold only objects.
6. For any requirement, there is no ready method support compulsory programmer has to code explicitly.
For every requirement ready made method support is available. Being a programmer we have to know how to use those methods and we are not responsible to implement those.
i want some program syntex difference.....
ReplyDeletei also need
Deletei also need
Deletegood
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
Deletecan you please explain how Array can hold homogeneous and collection can hold heterogeneous and homogeneous ........
ReplyDeleteArray
Case 1:
int a[]=new int[5];
Case2:
Object[] s=new Object[5];
s[0]=new Classname();
s[1]=12;
s[2]=12.00;
Collection
case 3:
ArrayList in=new ArrayList(); here data type is Integer
in.add(100);
in.add("");---->CTE
Case 4:
ArrayList in=new ArrayList(); Default it as a Object
in.add(new ClassName());
in.add("");
in.add(10);
in case 2 and case 4 we can able to store different type of Objects,so how we can say Array is homogeneous,
Thanks & Regards,
Karthik....
I've same doubt this, please reply
Deletecan you elaborate on your 2nd point(Memory point of view arrays are not recommended to use) by giving an example.. Thank you
ReplyDeleteArray is not expand the memory size when more memory require at run time but collection will expanded the memory size when its require more memory at run time..
Deleteplease explain on 3rd point.....(Performance) with some code
ReplyDeleteFrom the above conversation wat i thought was we can remove Array concepts from the world.
ReplyDeleteBut why no body remove it.
nice ha eruku
ReplyDeleteThis comment has been removed by the author.
ReplyDeletethis is durga sir meterial
ReplyDeleteDifference Between Array and Collection
ReplyDeleteThanks for sharing this post.
good ans
ReplyDeletegood ans
ReplyDelete