Tammi Armstrong wrote:For instance, I stored "William" as the key and " 7 421,592" as the object. "7" is the rank for the name William & "421,592" is the number of births associated with William.
OK, but you might want to read the
StringsAreBad article before you go any further.
It's true that you have a lot of strings to deal with; but you need to understand
what they represent.
It's fairly obvious that "William" is just a name, but what about "7 421,592"? It would seem to be some sort of ranking information, but maybe you can come up with a better name.
It also appears to be the same for both boys and girls, so you can probably use the same object to hold it for both,
So you might come up with something like
and then you could use a
Map<String, NameInfo>. And
this is what we mean by creating classes to meet your needs.
For a problem this simple you
could possibly get away with just using strings, but IMO it's a bad habit to get into, because you'll soon run into problems where
Strings simply aren't good enough.
Read the article above, and see if what I said makes any more sense.
HIH
Winston
PS: If you're only worried about converting a
String to an
int (or an
Integer), have a look at
Integer.parseInt(String) or
Integer.valueOf(String).