Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How do i use the bollean isEmpty on an array list

Reply
Thread Tools

How do i use the bollean isEmpty on an array list

 
 
ron
Guest
Posts: n/a
 
      06-30-2003
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


 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      06-30-2003
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 ((E-Mail Removed)) ---------------------------\
| 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
 
Reply With Quote
 
 
 
 
Phil Hanna
Guest
Posts: n/a
 
      07-01-2003
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const and array of array (of array ...) Mara Guida C Programming 3 09-03-2009 07:54 AM
list of countries File v. Array v. HTML list slinky ASP .Net 1 06-18-2007 08:01 PM
length of an array in a struct in an array of structs in a struct in an array of structs Tuan Bui Perl Misc 14 07-29-2005 02:39 PM
array of char array in headerfile (string list) - some questions sigi C++ 4 07-03-2005 04:17 PM
Length of Array of Array of Array Tom Perl Misc 3 12-20-2004 05:23 PM



Advertisments