What are differences between arrays and collections?

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.

18 comments:

  1. i want some program syntex difference.....

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  3. can you please explain how Array can hold homogeneous and collection can hold heterogeneous and homogeneous ........

    Array
    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....

    ReplyDelete
  4. can you elaborate on your 2nd point(Memory point of view arrays are not recommended to use) by giving an example.. Thank you

    ReplyDelete
    Replies
    1. Array 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..

      Delete
  5. please explain on 3rd point.....(Performance) with some code

    ReplyDelete
  6. From the above conversation wat i thought was we can remove Array concepts from the world.
    But why no body remove it.

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete