Results 1 to 7 of 7
  1. #1
    Shyam Singh is offline Member
    Join Date
    Jun 2008
    Posts
    48
    Rep Power
    0

    Question who can i do it ?

    who can i do it ?

    Want to store string ,int, double in single array .

    I want Heterogeneous collection array .... pls give a simple exaple of this type of array.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    An array is a collection of same type elements. What do all the items you want to store in an array have in common? That would be the type of the array. Since there they have nothing in common, you can't store them in an array: int and double are primitives, String is a class. If you use Integer and Double then all the elements would be Objects and you could store them in Object[] array.

  3. #3
    Shyam Singh is offline Member
    Join Date
    Jun 2008
    Posts
    48
    Rep Power
    0

    Default

    Norm could u pls give me a simple example of object array with
    with diff. data types in the class ... i just need a small example..

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Object[] array = new Object[2];
    array[0] = "First";
    array[1] = new Integer(2);

  5. #5
    Niveditha's Avatar
    Niveditha is offline Senior Member
    Join Date
    May 2008
    Posts
    307
    Rep Power
    7

    Default

    Ya, that was a nice solution norm.

    Shyam you can even use array of arrays. An array having arrays of different data type.
    To finish sooner, take your own time....
    Nivedithaaaa

  6. #6
    Shyam Singh is offline Member
    Join Date
    Jun 2008
    Posts
    48
    Rep Power
    0

    Default

    hi Norm
    can i do it by using Vector class . i hav a example of vector class i m tring with that.
    if u hav a ex. of object array prog. pls give me one. that will be really helpfull.
    thanks

  7. #7
    Shyam Singh is offline Member
    Join Date
    Jun 2008
    Posts
    48
    Rep Power
    0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •