Results 1 to 4 of 4
  1. #1
    kev3kev3 is offline Member
    Join Date
    Apr 2012
    Posts
    13
    Rep Power
    0

    Default Array List Question....

    I would like to know if it is possible to remove an element from an array list by stating a variable of the object I'm trying to remove.

    So I have the following remove method, where person is an object that includes a first name and last name, etc. Group is the Array List that I have.

    public void remove (Person a)
    {
    group.remove (a);
    }

    So is there anyway of using the remove method to state a surname for example and remove the element. This is instead of group.remove (0) and just stating the element in the Array List.

    I hope this makes some kind of sense.

    Help is massively appreciated...

    Thanks

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default Re: Array List Question....

    So, let me see if I understand: you have a List of Persons, and a Person can contain a name? And you want to be able to remove the Person with a specific name from the List?

    Sounds like a job for a Map.

    Or you could iterate over the List until you find a Person with that name and then remove it.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    kev3kev3 is offline Member
    Join Date
    Apr 2012
    Posts
    13
    Rep Power
    0

    Default Re: Array List Question....

    OK, one other thing. If I wanted add a Person to the list and wanted them to be added alphabetically by surname, then by first name for instance. What would be the best way to store the Person objects?

  4. #4
    jlczuk is offline Senior Member
    Join Date
    Apr 2012
    Location
    New York State of Confusion, USA
    Posts
    137
    Blog Entries
    1
    Rep Power
    0

    Default Re: Array List Question....

    This sounds like a job for SortedMap. Whenever you are doing anything with collections, you should checkout the Collections API to learn what goodies it has to offer. I'm hoping you don't need a link to the Oracle site to get to the doc.

Similar Threads

  1. Hello All a little List question...
    By AnteeN in forum New To Java
    Replies: 11
    Last Post: 12-07-2011, 12:36 PM
  2. Linked List, Array List time complexity
    By Rick99771977 in forum New To Java
    Replies: 4
    Last Post: 08-18-2011, 05:37 AM
  3. Replies: 2
    Last Post: 09-06-2010, 01:03 AM
  4. Need help with array list jpanel question!!! Plz help!!!
    By helpmeplease in forum New To Java
    Replies: 17
    Last Post: 12-11-2009, 12:37 PM
  5. Linked List Question
    By CirKuT in forum New To Java
    Replies: 4
    Last Post: 12-10-2008, 06:56 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
  •