Results 1 to 14 of 14
- 05-02-2012, 02:34 AM #1
Member
- Join Date
- Jan 2012
- Posts
- 16
- Rep Power
- 0
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:
which contain the following data:Java Code:private Map <String, ArrayList<String>> variousPerformers; private Map <String,ArrayList<Integer>> daysAvailable;
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:
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)
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(?)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); } } }
- 05-02-2012, 03:15 AM #2
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.
- 05-02-2012, 11:21 PM #3
Member
- Join Date
- Jan 2012
- Posts
- 16
- Rep Power
- 0
Re: Help searching arraylists in hashmaps
the desired out put is a list created from the arguments which are whodoesact and whenavilable
- 05-02-2012, 11:25 PM #4
Re: Help searching arraylists in hashmaps
Wouldn't TypeOfAct be one of the requirements?arguments which are whodoesact and whenavilableIf you don't understand my response, don't ignore it, ask a question.
- 05-02-2012, 11:39 PM #5
Member
- Join Date
- Jan 2012
- Posts
- 16
- Rep Power
- 0
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:
seems to doJava Code:for(String selectScan : variousPerformers.keySet()) { if(selectScan.contains(performerSelect)) { performerList = variousPerfomers.get(selectScan); } }
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
- 05-02-2012, 11:45 PM #6
Member
- Join Date
- Jan 2012
- Posts
- 16
- Rep Power
- 0
Re: Help searching arraylists in hashmaps
i cant get my head round how I search the arraylist within the hashmap basically
- 05-02-2012, 11:47 PM #7
Re: Help searching arraylists in hashmaps
You have two maps:type of act ie clown and required day ie 3
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.
- 05-02-2012, 11:48 PM #8
Member
- Join Date
- Jan 2012
- Posts
- 16
- Rep Power
- 0
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 dayLast edited by trying; 05-03-2012 at 01:47 AM.
- 05-02-2012, 11:50 PM #9
Member
- Join Date
- Jan 2012
- Posts
- 16
- Rep Power
- 0
- 05-02-2012, 11:50 PM #10
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.
- 05-02-2012, 11:52 PM #11
Member
- Join Date
- Jan 2012
- Posts
- 16
- Rep Power
- 0
- 05-02-2012, 11:57 PM #12
Member
- Join Date
- Jan 2012
- Posts
- 16
- Rep Power
- 0
- 05-02-2012, 11:58 PM #13
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.
- 05-03-2012, 01:46 AM #14
Member
- Join Date
- Jan 2012
- Posts
- 16
- Rep Power
- 0
Similar Threads
-
Maps and HashMaps
By moonah in forum Advanced JavaReplies: 1Last Post: 01-26-2012, 03:22 PM -
hashmaps
By santa in forum New To JavaReplies: 6Last Post: 05-03-2011, 11:07 PM -
Concerning HashMaps
By hjensen in forum New To JavaReplies: 7Last Post: 10-18-2010, 03:36 PM -
HashMaps get key for a specific value
By andre1011 in forum Advanced JavaReplies: 2Last Post: 03-11-2009, 02:30 AM -
recursively searching through arraylists
By newtojava7 in forum New To JavaReplies: 1Last Post: 03-17-2008, 02:36 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks