aspose file tools*
The moose likes Beginning Java and the fly likes what data structure is appropriate for me? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what data structure is appropriate for me?" Watch "what data structure is appropriate for me?" New topic
Author

what data structure is appropriate for me?

James Byars
Ranch Hand

Joined: Apr 15, 2009
Posts: 42
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

Joined: Jan 28, 2008
Posts: 5575

Map?
Kurt Van Etten
Ranch Hand

Joined: Sep 07, 2010
Posts: 98
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

Joined: Aug 31, 2004
Posts: 11343

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.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Vinod Vinu
Ranch Hand

Joined: Aug 30, 2009
Posts: 217
go for Map buddy


Vinod Kumar Nair
"Any fool can write code that a computer can understan. Good programmers write code that humans can understand."
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

If you end up using tuples, you should probably use ArrayList. Vector is old and tired.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what data structure is appropriate for me?