Results 1 to 14 of 14
  1. #1
    trying is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default Help searching arraylists in hashmaps

    hi all I have a quick quest on searching hashmaps

    I am writing a method which takes 2 augments in attempt to find a what performers on specific day however im really struggling - any guidelines you can give would be appreciated

    I currently have 2 hasmaps set up:

    Java Code:
        private Map <String, ArrayList<String>> variousPerformers;
        private Map <String,ArrayList<Integer>> daysAvailable;
    which contain the following data:

    variousPerfomers:
    String[] performers = {"Jugglers", "Comedians",
    "Clowns", "Magicians"};

    String[][] actsWhoPerformWhat =
    {
    {"Barry", "Will", "Eric", "Billy", "Carol", "Steve", "Daz",
    "Jerry", "Julie", "Clark"},
    {"Clark", "Mark", "Tim", "Eric", "Carol", "Waye", "Ed",
    "Dan", "Julie", "Clark", "Zoe"},
    {"Tim", "Eric", "Will", "Billy", "Wayne", "Dan", "Julie",
    "Jerry", "Barry", "Steve", "Daz", "Dom", "Oli", "Ed",
    "Jim"},
    {"Oli", "Jerry", "Barry", "Clark", "Carol", "Daz", "Ed",
    "Zoe", "Steve", "Wayne", "Fred"}
    };

    daysAvailable
    String[] performersList =
    {"Barry", "Will", "Eric", "Billy", "Carol", "Steve", "Daz",
    "Jerry", "Julie", "Clark", "Mark", "Tim", "Eric", "Carol", "Waye", "Ed",
    "Dan","Zoe", "Billy", "Dan", "Dom", "Oli", "Jim", "Fred"}

    Integer[][] daysAvailable =
    {
    {12,2}, {3,6,14}, {1,10,12}, {3,9}, {12,14},
    {4,8,10}, {6}, {8,2,4}, {1,2,12}, {7,10,14}, {10,11},
    {7,13,14}, {5}, {3,4,4}, {8}, {10}, {}, {4,8,12}, {8,11,14},
    {4,5,14}, {4,8,14}, {4,10,14}, {7,10,14}, {5,10,14}
    }

    The method which I want to write should search the first map of the and for the act search the second map for the day based on a 14 day period:

    Java Code:
    public void findPerformerTypeAndDay(String performerSelect, int daySelect)
    with the full code below I am managing to return all of the names which do a specified performance, however cant figure out how to search the second map using the int daySelect to return all the keys on that day.


    Java Code:
     
     public void findPerformerTypeAndDay(String performerSelect, int daySelect)
        {
            List<String> performerList = new ArrayList<String>();
            List<Integer> selectDayList = new ArrayList<Integer>();
            for(String selectScan : variousPerformers.keySet())
            {
               if(selectScan.contains(performerSelect))
               {
                  performerList = variousPerfomers.get(selectScan);
                }
             }
             for(ArrayList selectScanInt : daysAvailable.values())
             {
              if(selectScanInt.contains(daySelect))
              {
                   selectDayList = daysAvailable.get(selectScanInt) 
                }
                 
             
             System.out.println(selectDayList);
             System.out.println(performerList);
        }
    
    }
    }
    these are set to system.out.println for test at moment however the idea is to return a list as return statement one the values have been obtained and Im guessing intersected(?)

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,272
    Rep Power
    25

    Default Re: Help searching arraylists in hashmaps

    Try writing some pseudo code for the logic before trying to write the java code.
    You have two maps:
    TypeOFAct -> whoDoesAct
    whoDoesAct -> WhenAvailable

    Given: TypeOfAct
    What is the desired output: a list of whoDoesAct for a given day?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    trying is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default Re: Help searching arraylists in hashmaps

    the desired out put is a list created from the arguments which are whodoesact and whenavilable

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,272
    Rep Power
    25

    Default Re: Help searching arraylists in hashmaps

    arguments which are whodoesact and whenavilable
    Wouldn't TypeOfAct be one of the requirements?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    trying is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default Re: Help searching arraylists in hashmaps

    sorry i meant the augments are type of act ie clown and required day ie 3

    the method should then pull up a list of performers acting as clowns which:

    Java Code:
            for(String selectScan : variousPerformers.keySet())
            {
               if(selectScan.contains(performerSelect))
               {
                  performerList = variousPerfomers.get(selectScan);
                }
             }
    seems to do

    I then need the method to search the second hashmap for for all performers who are available on that day, and can act as clowns

  6. #6
    trying is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default Re: Help searching arraylists in hashmaps

    i cant get my head round how I search the arraylist within the hashmap basically

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,272
    Rep Power
    25

    Default Re: Help searching arraylists in hashmaps

    type of act ie clown and required day ie 3
    You have two maps:
    TypeOFAct -> whoDoesAct
    whoDoesAct -> WhenAvailable

    The logic would be something like this:
    1) get list of whoDoesAct using TypeOfAct
    2) for each whoDoesAct, get the list of WhenAvailable
    3) Look through the list of WhenAvailable dates for a match on required day and save WhoDoesAct for match.
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    trying is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default Re: Help searching arraylists in hashmaps

    as running the method:

    em.findPerformerTypeAndDay(String clown, int 5)

    returns:

    [Tim, Fleur, Will, Bill, Bella, Dan, Jill, Rose, Greg, Abe, Sally, Yuri, Olive, Sal, Jim]
    [] - he value which I want to reflect the int search representing the day
    Last edited by trying; 05-03-2012 at 01:47 AM.

  9. #9
    trying is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default Re: Help searching arraylists in hashmaps

    Quote Originally Posted by Norm View Post
    You have two maps:
    TypeOFAct -> whoDoesAct
    whoDoesAct -> WhenAvailable

    The logic would be something like this:
    1) get list of whoDoesAct using TypeOfAct
    2) for each whoDoesAct, get the list of WhenAvailable
    3) Look through the list of WhenAvailable dates for a match on required day and save WhoDoesAct for match.
    logic is always easier said than done :)

    Soldering on!

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,272
    Rep Power
    25

    Default Re: Help searching arraylists in hashmaps

    What problem are you working on now? How does post#8 relate to the rest of this thread?

    Take the steps listed in the logic and do them one at a time.
    Copy the step as a comment into the code and then write the code to do it.
    Last edited by Norm; 05-02-2012 at 11:52 PM.
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    trying is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default Re: Help searching arraylists in hashmaps

    Quote Originally Posted by Norm View Post
    What problem are you working on now? How does the last post relate to the rest of this thread?

    Take the steps listed in the logic and do them one at a time.
    Copy the step as a comment into the code and then write the code to do it.
    which post ?

  12. #12
    trying is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default Re: Help searching arraylists in hashmaps

    Quote Originally Posted by trying View Post
    as running the method:

    em.findPerformerTypeAndDay(String clown, int 5)

    returns:

    [Tim, Fleur, Will, Bill, Bella, Dan, Jill, Rose, Greg, Abe, Sally, Yuri, Olive, Sal, Jim]
    [] - he value which I want to reflect the int search representing the day
    is what is returned when run the method
    Last edited by trying; 05-03-2012 at 01:47 AM.

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,272
    Rep Power
    25

    Default Re: Help searching arraylists in hashmaps

    I have no idea what your post #12 is about.
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    trying is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default Re: Help searching arraylists in hashmaps

    thats because it didnt make much sense lol - tired grouchy and frustrated.

Similar Threads

  1. Maps and HashMaps
    By moonah in forum Advanced Java
    Replies: 1
    Last Post: 01-26-2012, 03:22 PM
  2. hashmaps
    By santa in forum New To Java
    Replies: 6
    Last Post: 05-03-2011, 11:07 PM
  3. Concerning HashMaps
    By hjensen in forum New To Java
    Replies: 7
    Last Post: 10-18-2010, 03:36 PM
  4. HashMaps get key for a specific value
    By andre1011 in forum Advanced Java
    Replies: 2
    Last Post: 03-11-2009, 02:30 AM
  5. recursively searching through arraylists
    By newtojava7 in forum New To Java
    Replies: 1
    Last Post: 03-17-2008, 02:36 AM

Posting Permissions

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