what is the best solution to create an array of variable size.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SUNIL TYATA
    New Member
    • Feb 2010
    • 18

    #1

    what is the best solution to create an array of variable size.

    If any body could give me the solution of how to create and array of variable size in java or in c++ (Note: except the linked list concept).
    Please!
    would be very appriciable Thank you!
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Since you've posted this question in the C forum I recommend that you look up malloc.

    Java has garbage collection and is quite a bit different. There are quite a few different classes that you can use instead of an array. I recommend you check out the ArrayList class.

    -Frinny

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      If you are using C++ you should avoid malloc which is a C function.

      If you really want to handle the memory allocation yourself then use new. However if you would like all them memory allocation handled for you use a vector<>

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Oh my, it's been a long time since I've used C++.
        How did I forget that my favorite thing about it, when I was learning it, was the "new" keyword!

        Thanks Banfa!

        -Frinny

        Comment

        Working...