Results 1 to 15 of 15
- 04-28-2012, 12:38 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 88
- Rep Power
- 0
Manipulating Map data help needed please ;)
Hey folks,
I'm still on these maps and arrays.
I have a method that takes a String argument -and I have a map that has keys that are mapped to ArrayLists containing lists of varying sizes with names(Strings).XML Code:someMethod(String aString)
When I execute the method with a name as the argument - the method needs to search through the map and move the name to the back of each ArrayList that it appears in (it may appear in more than one of the ArrayLists).
I'm really puzzled with this one. I think I need to move the lists from the map to a new list and then use indexOf to move the String name but I'm not sure.
Any help or advice is appreciated as always guys ;)
Regards
- 04-28-2012, 02:09 PM #2
Re: Manipulating Map data help needed please ;)
Can you make a detailed list of the steps the method is supposed to do?
When you get the list start working on the items in the list one at a time.
Post the list and the code that you are currently working on and your questions.If you don't understand my response, don't ignore it, ask a question.
- 04-28-2012, 02:35 PM #3
Member
- Join Date
- Mar 2012
- Posts
- 88
- Rep Power
- 0
Re: Manipulating Map data help needed please ;)
Ok, thanks Norm.
I have a method with the headerI have a map -XML Code:someMethod(String aString)
For example, the Keys in the map are 'Football Teams' and the ArrayList<String> are rosters of players. I have 4 keys which equals 4 rosters of players in this particular map.XML Code:Map<String, ArrayList<String>> someMap;
If I execute the method (aString will be a players name) then the method must move this name to the end of every roster that this name is included in.
If the method works, when I check the map, the name(aString) should have been moved to the end of each roster.
I haven't written any code so far ;(
Regards
- 04-28-2012, 02:41 PM #4
- 04-28-2012, 02:58 PM #5
Member
- Join Date
- Mar 2012
- Posts
- 88
- Rep Power
- 0
Re: Manipulating Map data help needed please ;)
lol - cool - i'll be back with what i've written in a bit ;)
- 04-28-2012, 04:45 PM #6
Member
- Join Date
- Mar 2012
- Posts
- 88
- Rep Power
- 0
Re: Manipulating Map data help needed please ;)
This is what I have so far then.
The println was just to see I had got a list of the rosters.XML Code:public void someMethod(String aString) { for(String eachRoster : someMap.keySet()) { List<String> roster = someMap.get(eachRoster); System.out.println(roster); } }
So this gives me the list (I think) that needs to be manipulated. How do i search this list for each occurrence of the string argument and then move it to the end of each 'roster' and then return this back to the map?
- 04-28-2012, 05:02 PM #7
Re: Manipulating Map data help needed please ;)
The List interface/class has methods for getting to its contents.this gives me the list
Have you worked out the detailed logic for what the method is supposed to do? Write a list of the steps in pseudo code.
What is the someMethod method supposed to do. It needs a new name that describes what it is going to do.If you don't understand my response, don't ignore it, ask a question.
- 04-28-2012, 05:11 PM #8
Member
- Join Date
- Mar 2012
- Posts
- 88
- Rep Power
- 0
Re: Manipulating Map data help needed please ;)
Thanks Norm.
The method I've written so far goes
The Map qualifiedDrivers has 4 keys which are vehicles and these are mapped to ArrayLists(Strings) of names(which are basically the rosters).XML Code:public void putDriverLastInRosters(String aString) { for(String eachRoster : qualifiedDrivers.keySet()) { List<String> roster = qualifiedDrivers.get(eachRoster); System.out.println(roster); } }
So the Map goesThe method should move the driver(String argument) to the end of ALL rosters in which it appears.XML Code:qualifiedDrivers<String, ArrayList<String>>();
Regards
- 04-28-2012, 05:30 PM #9
Re: Manipulating Map data help needed please ;)
Be sure to ask a question when you have one.
If you don't understand my response, don't ignore it, ask a question.
- 04-28-2012, 05:38 PM #10
Member
- Join Date
- Mar 2012
- Posts
- 88
- Rep Power
- 0
Re: Manipulating Map data help needed please ;)
How do I find the String argument in the list and then move it to the end of each roster?
Regards
- 04-28-2012, 05:43 PM #11
Re: Manipulating Map data help needed please ;)
Look at the API doc for the List interface/class for methods to get at its contents.How do I find the String argument in the list
What are the steps to take to move something from one position in a list to another position? When you get those steps, then look at the API doc for those lists to find the methods to do each of the steps.move it to the endIf you don't understand my response, don't ignore it, ask a question.
- 04-28-2012, 05:47 PM #12
Member
- Join Date
- Mar 2012
- Posts
- 88
- Rep Power
- 0
Re: Manipulating Map data help needed please ;)
ok, I'll have another go Norm ;) Thanks for the advice.
Regards
- 04-28-2012, 09:24 PM #13
Member
- Join Date
- Mar 2012
- Posts
- 88
- Rep Power
- 0
Re: Manipulating Map data help needed please ;)
I got it working by the way - can't believe how simple it actually was. Using the API is vital for getting your head round these. Cheers for not telling me the direct answer ;)
Regards
- 04-28-2012, 09:31 PM #14
Re: Manipulating Map data help needed please ;)
I use the API dozens of times a day. Getting familiar with it is a requirement for programming.
Also be sure to look at the tutorial:
The Really Big IndexLast edited by Norm; 04-28-2012 at 09:41 PM.
If you don't understand my response, don't ignore it, ask a question.
- 04-28-2012, 09:36 PM #15
Member
- Join Date
- Mar 2012
- Posts
- 88
- Rep Power
- 0
Similar Threads
-
Manipulating strings
By gaborn415 in forum New To JavaReplies: 6Last Post: 04-07-2011, 09:45 PM -
Data Entry Workers Needed Worldwide
By rajshree in forum Jobs OfferedReplies: 0Last Post: 01-30-2011, 06:10 AM -
assigning strings and int from a file and then manipulating the data
By NDBASS in forum EclipseReplies: 1Last Post: 11-04-2010, 02:42 PM -
Manipulating URLs
By TheFlying_Boy in forum NetworkingReplies: 0Last Post: 08-03-2009, 05:01 PM -
Manipulating XML
By JosephMConcepcion in forum XMLReplies: 2Last Post: 04-26-2009, 12:01 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks