wood burning stoves 2.0*
The moose likes Performance and the fly likes Map<Integer, String> or String[] ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Map<Integer, String> or String[] ?" Watch "Map<Integer, String> or String[] ?" New topic
Author

Map<Integer, String> or String[] ?

Vishal Srivastav
Ranch Hand

Joined: Nov 29, 2008
Posts: 46

Hi Friends,

I am creating a Java EE client where I need to make a call to a node (js) server to get the response. So I made a single class through which requests are made to node server.
Everytime I get a response, I need to send back the response code and the response itself. So I thought of creating a String array which would contain the response code and the response.

Here is my class:



But I am not convinced by creating too much string objects which would cause performance issues. So I thought of creating a Map<Integer, String> which would send back the response code and the response.



But again, creating a map with integer and checking everytime the response code creates overhead of boxing and unboxing of Integer object, which again could result in performance.



Which one should I use? Or is there any better alternative out of it?


Vishal Srivastava, Software Engineer (Android), Paradigm Creatives
SCJP 5, SCWCD 5 - http://in.linkedin.com/in/srivastavavishal
Claude Moore
Ranch Hand

Joined: Jun 24, 2005
Posts: 430
    
    1

As from your code excerpt, I see that you'll send back for each response exactly two string values. I think that with so few data to be sent, performance overhead should be negligible; I just only guess that from a JSON's perspective, handling string arrays instead of maps would be more efficient. But it's just a guess.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Map<Integer, String> or String[] ?
 
Similar Threads
Jersey RESTful web service - How to post XML file using jersey framework
webservice calling from url
JSF 2.0 and REST(Jeresy) Integratio
Jersey REST -(Un)Marshaller
AJAX response to a Restful Jersey Resource