Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what data structure is appropriate for me?

 
James Byars
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

i am writing a program where i will have a list of two objects, the first will be a string, and the second an integer.

e.g.

list = ((string1, int1), (string2, int2) ... (stringN, intN))

i then have to go through the list of these two objects, look at intX, do some calculation on it, and depending on the result, put (stringX, intX) it into another list.

can someone please suggest to me what data structure would be best to use for (stringN, intN). I am just thinking of simply having a Vector for each (stringN, intN) i.e. have a list of Vectors, but maybe there is a better way?

thanks
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Map?
 
Kurt Van Etten
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could create a little class consisting of just the two data members. That might have a little less overhead than using one of the container classes. (Then again, maybe not. I've never tried comparing the two approaches to see if there's a measurable difference, but it might make an interesting experiment.)
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Seetharaman suggested, paired values sounds like a Map -- but only if one of your elements (either the String or the int) can be used as a unique key for the pair. If that's not the case, then Kurt's suggestion of a special class makes sense.
 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
go for Map buddy
 
Stephan van Hulst
Bartender
Pie
Posts: 5432
52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you end up using tuples, you should probably use ArrayList. Vector is old and tired.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic