2 dimensional-Array or Map

Discussion in 'Java' started by Rizwan, Jan 4, 2005.

  1. Rizwan

    Rizwan Guest

    which one is faster? I have a scenario where i can use either one. which one
    is better performance wise?

    Thanks
     
    Rizwan, Jan 4, 2005
    #1
    1. Advertising

  2. Rizwan

    Rizwan Guest

    its a String array. the Map will also contain Strings as key and value.

    "Rizwan" <> wrote in message
    news:5cGCd.7535$...
    > which one is faster? I have a scenario where i can use either one. which

    one
    > is better performance wise?
    >
    > Thanks
    >
    >
     
    Rizwan, Jan 4, 2005
    #2
    1. Advertising

  3. Rizwan

    Ann Guest

    "Rizwan" <> wrote in message
    news:5cGCd.7535$...
    > which one is faster? I have a scenario where i can use either one. which

    one
    > is better performance wise?
    >
    > Thanks
    >

    If it is very small, array is faster, if it is very big, map is faster.
     
    Ann, Jan 5, 2005
    #3
  4. Ann wrote:
    > If it is very small, array is faster, if it is very big, map is faster.


    Why do you think so?

    Array access is ALWAYS much faster than accessing a Map. Unless you're
    talking about a case where the array is sparsely populated and gets so
    big that it has to be swapped out.
     
    Michael Borgwardt, Jan 5, 2005
    #4
  5. Rizwan

    Chris Uppal Guest

    Michael Borgwardt wrote:

    > Ann wrote:
    > > If it is very small, array is faster, if it is very big, map is faster.

    >
    > Why do you think so?


    I suspect Rizwan (the OP) was considering a Map<String, String> vs. a 2-column
    array of Strings holding keys in one column and values in the other, and using
    a linear search. I assume that Ann was thinking the same thing, certainly her
    answer was completely correct for that case.

    -- chris
     
    Chris Uppal, Jan 5, 2005
    #5
    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. Alf P. Steinbach
    Replies:
    0
    Views:
    454
    Alf P. Steinbach
    Aug 18, 2003
  2. John Harrison
    Replies:
    4
    Views:
    6,955
    Default User
    Aug 19, 2003
  3. Icosahedron
    Replies:
    8
    Views:
    687
    Vivek
    Aug 21, 2003
  4. Venkat
    Replies:
    4
    Views:
    1,014
    Venkat
    Dec 5, 2003
  5. Wirianto Djunaidi
    Replies:
    2
    Views:
    228
    Wirianto Djunaidi
    Apr 29, 2008
Loading...

Share This Page