CSE 116 Lecture Notes - Lecture 9: Iterator, Null Set, Class Invariant

38 views3 pages

Document Summary

Why important: breaks up code into separate class for each function, each part replaceable when better approach found, like legos each piece is separate, but connectable in various ways. Iterator interface: package java. util, public interface iterator { boolean hasnext(); *** iterator provides data but is a separate class*** Uses cursor to mark location to be used. Data external to iterator (like a cursor, when the application runs, it uses and moves cursor around) Moves forward item-by-item only, can"t jump around: methods are very, very limited since the iterator instance has no data, it may be tempting to modify data, but can only process data using an iterator. Iterable interface: package java. lang, public interface iterable { public iterator iterator(); for each loop, for (type variablename : iterablevar, can work with almost any collection class i. e. arraylist & multiset. Algoirthm next() if hasnext() then (see slide) end. Comparing implementations see slide for arraylist iterator and arraymultiset iterator.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents