storing mixed data type of data into an array? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

storing mixed data type of data into an array?

insertnamehereinsertnamehere Posts: 1Member
How would I store a mix data type of int and String in an array? I need to input an id number and name(15 Jones) and then store it in an array, and then list in numerical order. Help?

And I can't use a vector.




Comments

  • DariusDarius Posts: 1,666Member
    : How would I store a mix data type of int and String in an array? I need to input an id number and name(15 Jones) and then store it in an array, and then list in numerical order. Help?
    :
    : And I can't use a vector.

    This is the type of thing for structs (structures). Unfortunately, Java doesn't have structures. Fortunately, classes and structures are nearly identical (in C++ there is only one minor technical difference between them). The reason it's unfortunate that Java doesn't have structures is that though similar they have different intents. Java's not a pure enough OO language to really counter this argument with arguments about purity. Any argument about structures violating OO principles is absurd, limiting the programmer to any one paradigm is ridiculous.

    Anyways, there's your answer. Use a Class that holds the String and the int. You can violate OO and have them just be public members with no methods, or you can make accessors/modifiers and hide away that string and int. Depending on what you are going for one will be better than the other.

    "We can't do nothing and think someone else will make it right."
    -Kyoto Now, Bad Religion

Sign In or Register to comment.