• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Map<Integer, String> or String[] ?

 
Vishal Srivastav
Ranch Hand
Posts: 46
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Claude Moore
Ranch Hand
Posts: 787
7
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic