dynamic allocation of mixed type arrays

Discussion in 'Java' started by gimme_this_gimme_that@yahoo.com, Mar 20, 2007.

  1. Guest

    I have a variable c defined like this:

    Object[][] c = {{"asdfa",new Long(0)},{"asdfa",new Long(0)}};

    Is there a way to define it so the number of elements is defined in
    brackets?

    Something like this:

    Object[][] c = new {new String(""),new Long(0),new Long(0)}[2];
    , Mar 20, 2007
    #1
    1. Advertising

  2. wrote:
    > I have a variable c defined like this:
    >
    > Object[][] c = {{"asdfa",new Long(0)},{"asdfa",new Long(0)}};
    >
    > Is there a way to define it so the number of elements is defined in
    > brackets?
    >
    > Something like this:
    >
    > Object[][] c = new {new String(""),new Long(0),new Long(0)}[2];
    >


    You can use:
    Object[][] c = new Object[2][3];
    Joshua Cranmer, Mar 20, 2007
    #2
    1. Advertising

  3. Daniel Pitts Guest

    On Mar 20, 2:24 pm, Joshua Cranmer <> wrote:
    > wrote:
    > > I have a variable c defined like this:

    >
    > > Object[][] c = {{"asdfa",new Long(0)},{"asdfa",new Long(0)}};

    >
    > > Is there a way to define it so the number of elements is defined in
    > > brackets?

    >
    > > Something like this:

    >
    > > Object[][] c = new {new String(""),new Long(0),new Long(0)}[2];

    >
    > You can use:
    > Object[][] c = new Object[2][3];



    I'm curious though, are you trying to make an array implementation of
    Map<String, Long> ?
    Daniel Pitts, Mar 21, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chishun Kwong
    Replies:
    0
    Views:
    411
    Chishun Kwong
    Mar 3, 2005
  2. Replies:
    5
    Views:
    363
    -berlin.de
    Dec 24, 2004
  3. Ken
    Replies:
    24
    Views:
    3,837
    Ben Bacarisse
    Nov 30, 2006
  4. chris
    Replies:
    6
    Views:
    972
    chris
    Oct 28, 2005
  5. Philipp
    Replies:
    21
    Views:
    1,109
    Philipp
    Jan 20, 2009
Loading...

Share This Page