Results 1 to 15 of 15
Like Tree1Likes
  • 1 Post By lannie1980

Thread: Manipulating Map data help needed please ;)

  1. #1
    lannie1980 is offline Member
    Join Date
    Mar 2012
    Posts
    88
    Rep Power
    0

    Default 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 -
    XML Code:
    someMethod(String aString)
    and I have a map that has keys that are mapped to ArrayLists containing lists of varying sizes with names(Strings).

    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

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

    Default 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.

  3. #3
    lannie1980 is offline Member
    Join Date
    Mar 2012
    Posts
    88
    Rep Power
    0

    Default Re: Manipulating Map data help needed please ;)

    Ok, thanks Norm.

    I have a method with the header
    XML Code:
    someMethod(String aString)
    I have a map -
    XML Code:
    Map<String, ArrayList<String>> someMap;
    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.

    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

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Manipulating Map data help needed please ;)

    Quote Originally Posted by lannie1980 View Post
    I haven't written any code so far ;(
    Time to start, then.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    lannie1980 is offline Member
    Join Date
    Mar 2012
    Posts
    88
    Rep Power
    0

    Default Re: Manipulating Map data help needed please ;)

    lol - cool - i'll be back with what i've written in a bit ;)
    DarrylBurke likes this.

  6. #6
    lannie1980 is offline Member
    Join Date
    Mar 2012
    Posts
    88
    Rep Power
    0

    Default Re: Manipulating Map data help needed please ;)

    This is what I have so far then.

    XML Code:
    public void someMethod(String aString)
       {
       for(String eachRoster : someMap.keySet())
       {
          List<String> roster = someMap.get(eachRoster);
          System.out.println(roster);
       }
    }
    The println was just to see I had got a list of the rosters.

    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?

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

    Default Re: Manipulating Map data help needed please ;)

    this gives me the list
    The List interface/class has methods for getting to its contents.
    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.

  8. #8
    lannie1980 is offline Member
    Join Date
    Mar 2012
    Posts
    88
    Rep Power
    0

    Default Re: Manipulating Map data help needed please ;)

    Thanks Norm.

    The method I've written so far goes

    XML Code:
    public void putDriverLastInRosters(String aString)
       {
       for(String eachRoster : qualifiedDrivers.keySet())
       {
          List<String> roster = qualifiedDrivers.get(eachRoster);
          System.out.println(roster);
       }
    }
    The Map qualifiedDrivers has 4 keys which are vehicles and these are mapped to ArrayLists(Strings) of names(which are basically the rosters).
    So the Map goes
    XML Code:
    qualifiedDrivers<String, ArrayList<String>>();
    The method should move the driver(String argument) to the end of ALL rosters in which it appears.

    Regards

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default 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.

  10. #10
    lannie1980 is offline Member
    Join Date
    Mar 2012
    Posts
    88
    Rep Power
    0

    Default 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

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Manipulating Map data help needed please ;)

    How do I find the String argument in the list
    Look at the API doc for the List interface/class for methods to get at its contents.
    move it to the end
    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.
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    lannie1980 is offline Member
    Join Date
    Mar 2012
    Posts
    88
    Rep Power
    0

    Default Re: Manipulating Map data help needed please ;)

    ok, I'll have another go Norm ;) Thanks for the advice.

    Regards

  13. #13
    lannie1980 is offline Member
    Join Date
    Mar 2012
    Posts
    88
    Rep Power
    0

    Default 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

  14. #14
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default 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 Index
    Last edited by Norm; 04-28-2012 at 09:41 PM.
    If you don't understand my response, don't ignore it, ask a question.

  15. #15
    lannie1980 is offline Member
    Join Date
    Mar 2012
    Posts
    88
    Rep Power
    0

    Default Re: Manipulating Map data help needed please ;)

    nice one Norm ;)

Similar Threads

  1. Manipulating strings
    By gaborn415 in forum New To Java
    Replies: 6
    Last Post: 04-07-2011, 09:45 PM
  2. Data Entry Workers Needed Worldwide
    By rajshree in forum Jobs Offered
    Replies: 0
    Last Post: 01-30-2011, 06:10 AM
  3. Replies: 1
    Last Post: 11-04-2010, 02:42 PM
  4. Manipulating URLs
    By TheFlying_Boy in forum Networking
    Replies: 0
    Last Post: 08-03-2009, 05:01 PM
  5. Manipulating XML
    By JosephMConcepcion in forum XML
    Replies: 2
    Last Post: 04-26-2009, 12:01 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
  •