C S 314 Lecture Notes - Lecture 6: Parsing, Coffee Filter, Carl Linnaeus

50 views5 pages

Document Summary

The java collection interface (in package java. util) provides a common way for various kinds of collections to be used. This may make it possible to change the kind of collection used by an application. The toarray method allows any collection to be converted easily to an array. Two iterator patterns can be used with collections. The first is a simple iteration through all elements: for ( anytype item : coll ) The second form allows more complicated processing, including removal of an item. Iterator itr = coll. iterator(); while ( itr. hasnext() ) { anytype item = itr. next(); // process item if ( ) itr. remove(); } In this pattern, an iterator object itr is created. This object can be queried to test whether any items remain using itr. hasnext(). If there are objects, itr. next() gets the next one. itr. remove()removes the last object returned by itr. next() and can only be used once until there is another call to itr. next() .

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents