I am trying to figure out what would be the best way to create an array (or vector) that has 2 types of fields. The first field is a string and the second field is a byte array. I've looked at collections, but I'm not sure how I'd code a solution for this. I was thinking of making an object with the 2 elements and then vectoring a collection of the object. Does that make sense?
If anyone has any suggestions, I'd really appreciate it.
Although I certainly don't want to discourage you from encapsulating the data in an object if that is warranted, you may also want to take a look at the Map<K, V> interface and its concrete implementations, especially HashMap and TreeMap. Maps use key value pairs. Since Sun can probably explain them better than I can, here is a link to their tutorial on Maps. [ March 17, 2006: Message edited by: Garrett Rowe ]
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Joined: Dec 15, 2005
Thanks for the tip Garrett, but I was thinking more along the line of a type array like you would do in VB. The map seems to limit my ability to do duplicate keys. I'm trying to store a byte array and a string identifier to tell me what is in the byte array. There will be more than one pair of string/byte elements.
I'm thinking the best thing to do is create a simple class of 2 arrays and create a collection. I think I have some learnin to do.
I'm thinking the best thing to do is create a simple class of 2 arrays and create a collection.
Not quite, I don't think, if you're suggesting a class with two parallel arrays. Instead create a simple class with a String and a byte as members, and then store instances of that class in some predefined collection type.