How do i use the bollean isEmpty on an array list

Discussion in 'Java' started by ron, Jun 30, 2003.

  1. ron

    ron Guest

    How do I use the Boolean isEmpty test on an array list. While in a 'while
    loop' ie continue till list is empty?
    The name of the array list is pList.
    Thanks for your help
     
    ron, Jun 30, 2003
    #1
    1. Advertising

  2. ron <thtf> scribbled the following:
    > How do I use the Boolean isEmpty test on an array list. While in a 'while
    > loop' ie continue till list is empty?
    > The name of the array list is pList.
    > Thanks for your help


    Don't they teach programming at your school any more? Here is the
    skeleton of the code you need to use.

    do {
    doMagicStuff(pList);
    } while (!pList.isEmpty());

    Note that if doMagicStuff() does not alter the contents of pList, then
    your loop will run either exactly once, or perpetually. This is because
    do...while loops themselves cannot change the state of ArrayLists.

    --
    /-- Joona Palaste () ---------------------------\
    | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
    | http://www.helsinki.fi/~palaste W++ B OP+ |
    \----------------------------------------- Finland rules! ------------/
    "C++ looks like line noise."
    - Fred L. Baube III
     
    Joona I Palaste, Jun 30, 2003
    #2
    1. Advertising

  3. ron

    Phil Hanna Guest

    On Mon, 30 Jun 2003 20:46:40 GMT, "ron" <thtf> wrote:

    >How do I use the Boolean isEmpty test on an array list. While in a 'while
    >loop' ie continue till list is empty?
    >The name of the array list is pList.
    >Thanks for your help


    Does the homework assignment explicitly say you have to use the
    isEmpty test? (I'm assuming that you are removing elements from the
    list somehow). Or can you use anything that works?

    If you just want to iterate over the list, the easiest thing to do is:

    for (Iterator it = pList.iterator(); it.hasNext(); ) {
    Object obj = it.next();
    // Do something with obj, casting it into
    // the appropriate type, if necessary
    }
    --
    Phil Hanna
    Author of JSP 2.0: The Complete Reference
    http://www.philhanna.com
    http://www.philhanna.com
     
    Phil Hanna, Jul 1, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. roopa
    Replies:
    6
    Views:
    766
    Jerry Coffin
    Aug 27, 2004
  2. dackz
    Replies:
    0
    Views:
    497
    dackz
    Feb 6, 2007
  3. Debajit Adhikary
    Replies:
    17
    Views:
    699
    Debajit Adhikary
    Oct 18, 2007
  4. OW Ghim Siong
    Replies:
    2
    Views:
    405
    Peter Otten
    Nov 30, 2010
  5. asil klin
    Replies:
    28
    Views:
    1,315
    Andreas Leitgeb
    Mar 5, 2011
Loading...

Share This Page