Results 1 to 4 of 4
  1. #1
    JK4
    JK4 is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default Collection that handles a key of String?

    I have a collection:
    A 10.10
    B 12.12
    C 32.32

    I will use the first field (letter) to look up the second field (number).

    Nothing fancy, only 90 entries, no need for sorting. Entries will be hard-coded. not even a need to edit.

    I can't find an example of a collection, dictionary, array, hash, etc. that accommodates Strings data type for the key.

    Any suggestions?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Collection that handles a key of String?

    All collections that take objects for a key can take a String.
    I don't know of any that do not.

    If you are getting errors, please copy and paste the full text of the error message here.

  3. #3
    JK4
    JK4 is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default Re: Collection that handles a key of String?

    Works perfect. Thank you very much. I found dozens of examples but every one used int for key.

    Can I extend the question?
    The objective is to convert the name of a piano key to its frequency. Collection Key is name of a piano key ("A4", "A#4" ... ) and Collection Value is the frequency (440.12, 452.34...). If data is 88 items, hard coded, added in alphabetical order by key, no additions or edits (read only) what is the best collection type?

    Thanks.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Collection that handles a key of String?

    what is the best collection type?
    Define best.
    How do you want to access the values?
    A Map would be the simplest.

Similar Threads

  1. Replies: 10
    Last Post: 05-21-2011, 02:47 PM
  2. Stack (collection) to int via String
    By aborgeld in forum New To Java
    Replies: 7
    Last Post: 04-07-2011, 06:16 PM
  3. Counting vowles in a collection of String objects
    By sunde887 in forum New To Java
    Replies: 4
    Last Post: 01-18-2011, 08:22 AM
  4. JDBC using adapter (and connection handles)
    By Gideonzx in forum Advanced Java
    Replies: 1
    Last Post: 07-28-2009, 07:54 AM
  5. Replies: 0
    Last Post: 12-28-2007, 01:25 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •