Results 1 to 2 of 2
  1. #1
    Pragz is offline Member
    Join Date
    Apr 2011
    Posts
    1
    Rep Power
    0

    Default ArrayList and remove()

    In class today we were learning about ArrayLists, and I thought of something. Would appending methods to the end of a .remove() element still work? For example:

    list.remove(index).exampleMethod();

    Is that okay or would I have to do:

    temp = list.remove(index);
    temp.exampleMethod();

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Try it and see! Or read the API documentation for that version of remove(). If it is documented to return something with an exampleMethod() then there is no reason why you can't call it.

    (This sort of chaining method calls together can become difficult to read - as evidence look around here for people who dump reams of NetBeans layout code.)

Similar Threads

  1. copying contents of an ArrayList to another ArrayList
    By ankit1801 in forum New To Java
    Replies: 8
    Last Post: 03-27-2011, 07:07 AM
  2. Replies: 7
    Last Post: 11-22-2010, 02:26 PM
  3. need help with the remove method on arrayList
    By ShinTec in forum New To Java
    Replies: 5
    Last Post: 02-16-2010, 10:38 AM
  4. Replies: 2
    Last Post: 04-21-2008, 12:43 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
  •