2 dimensional-Array or Map

R

Rizwan

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

Thanks
 
A

Ann

Rizwan said:
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.
 
M

Michael Borgwardt

Ann said:
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.
 
C

Chris Uppal

Michael said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top