Results 1 to 6 of 6
  1. #1
    jomypgeorge is offline Member
    Join Date
    May 2010
    Posts
    90
    Rep Power
    0

    Default collection issue

    hi friends

    i want to store employee data in a collection sorted with employee name. also i want to fetch employees with name starting with a given character.
    (for character scroll in window)
    i tried TreeMap with Structure <Character, Employee>. but it fails to add duplicate entries for a given character.
    i thought of using subset() method of TreeMap to fetch all Employees with a given character.

    how to handle this?
    thanks in advance.......

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Of course it does (fail that is) as that is how maps work. Simply loop through your list and check the names.

  3. #3
    jomypgeorge is offline Member
    Join Date
    May 2010
    Posts
    90
    Rep Power
    0

    Default

    any other solution?

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by jomypgeorge View Post
    any other solution?
    Maps and Sets require unique keys; the first character of a name doesn't make a unique key (not even the entire name makes a unique key); possibly you have to create a unique key given the empoyee ID as the minor comparison part, i.e. <name, ID> forms the unique key. Sorted Sets and Maps can iterate over sub sets and maps ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by jomypgeorge View Post
    any other solution?
    Why? What's wrong with that one?

    You could always create Map as
    Java Code:
    Map<Character, List<Employee>>
    of course.

  6. #6
    jomypgeorge is offline Member
    Join Date
    May 2010
    Posts
    90
    Rep Power
    0

    Default

    thanks josAH and masijade
    i did it with TreeMap<Character, TreeSet<Employee>>

    thanks a lot
    Last edited by jomypgeorge; 02-07-2011 at 01:03 PM.

Similar Threads

  1. Help me on Collection
    By kathir0301 in forum New To Java
    Replies: 1
    Last Post: 12-03-2010, 11:08 AM
  2. collection
    By D.Calladine in forum New To Java
    Replies: 1
    Last Post: 12-02-2010, 02:36 PM
  3. help for collection api
    By javastuden in forum New To Java
    Replies: 3
    Last Post: 02-24-2010, 11:52 AM
  4. collection framework
    By swati.jyoti in forum New To Java
    Replies: 8
    Last Post: 09-01-2009, 03:45 PM
  5. How to get NamingEnumeration from my collection?
    By hencre in forum Advanced Java
    Replies: 1
    Last Post: 10-18-2008, 08:01 PM

Posting Permissions

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