SlideShare a Scribd company logo
1 of 11
List and Iterator
List Interface
• Java has 3 classes which implement the List
Interface - LinkedList, ArrayList and Vector.
• How do you use the ArrayList in your
program?
• import java.util.*
• How to create a List object?
• List lst = new ArrayList();
• Can we do this? Why?
• List lst = new List();
• How to output the List object?
• With the List object, we don’t need to use
loop structure to print out each element,
simply output the List object. Only the output
will be surrounded by square brackets.
• Name some of the List methods.
• boolean isEmpty()
• int size()
• Object set(int index, Object o)
• void add(int index, Object o)
• boolean add(Object o)
• Iterator<E> iterator()
• Do we need to cast the element retrieved
from a list object?
• Yes, unless the list object was created using
type parameters, meaning?
• List doubleList = new ArrayList();
• /* fill in the Arraylist with some Double objects */
• Double aDouble = doubleList.get(0); => ok?
• List<Double> doubleList = new ArrayList<Double>();
List Interface
• List interface. What is an interface? P135
1) All methods in the interface are both public
and abstract.
2) Any class implementing the interface has to
implement every method, otherwise…
• More rule on p139.
Iterator
• What is Iteration?
• Iteration is a continual repeating of
something.
• What java structure fits this description?
• Loops are iteration structure
• What is an iterator?
• An iterator’a sole purpose is to traverse a
collection, one element at a time.
• Is Iterator a class?
• NO, it is an interface.
• What are the 3 methods of the Iterator?
• boolean hasNext(); E next(); void remove()
• How to use a generic iterator?
• List<String> list = new ArrayList<String>();
<code to initialize list with strings>
Iterator<String> itr = list.iterator();
while(itr.hasNext())
System.out.println(itr.next())
• What is above while loop equivalent to?
• for-each loop
practice
• Write down the answers on the paper.
• Write a generic List object of Integer.
• Get an iterator from the List object.
• Loop through the list and if the number is not
mutiples of 3, remove it.
What is wrong with the codes?
Iterator<someType) itr = list.iterator();
while(true)
System.out.println(itr.next());
Iterator<someType) itr = list.iterator();
someType ob= itr.next();
itr.remove();
itr.remove();
• What is the different to use iterator from for-
each loop
• Use a for-each loop for accessing and
modifying objects in a list. Use an iterator for
removal of objects.
Homework
• Read Barron’s chapter 7 and BPJ lesson 40
about recursion. Write down any notes that
you think are important. They can be in any
form like questions and answers, or simply
questions which you don’t understand.
Everyone has to submit at least 25 notes or
remarks.

More Related Content

What's hot

Presentation on python data type
Presentation on python data typePresentation on python data type
Presentation on python data typeswati kushwaha
 
data structures and algorithms Unit 1
data structures and algorithms Unit 1data structures and algorithms Unit 1
data structures and algorithms Unit 1infanciaj
 
Python data type
Python data typePython data type
Python data typenuripatidar
 
List Manipulation in FME
List Manipulation in FMEList Manipulation in FME
List Manipulation in FMESafe Software
 
Programming with Python - Week 3
Programming with Python - Week 3Programming with Python - Week 3
Programming with Python - Week 3Ahmet Bulut
 
Introduction to Python programming Language
Introduction to Python programming LanguageIntroduction to Python programming Language
Introduction to Python programming LanguageMansiSuthar3
 
Programming with Python - Week 2
Programming with Python - Week 2Programming with Python - Week 2
Programming with Python - Week 2Ahmet Bulut
 
The awesome algorithm
The awesome algorithmThe awesome algorithm
The awesome algorithmSazzad Hossain
 
Java Tutorial Lab 7
Java Tutorial Lab 7Java Tutorial Lab 7
Java Tutorial Lab 7Berk Soysal
 

What's hot (16)

Presentation on python data type
Presentation on python data typePresentation on python data type
Presentation on python data type
 
Unit 4
Unit 4Unit 4
Unit 4
 
data structures and algorithms Unit 1
data structures and algorithms Unit 1data structures and algorithms Unit 1
data structures and algorithms Unit 1
 
Es6 day3
Es6 day3Es6 day3
Es6 day3
 
Python data type
Python data typePython data type
Python data type
 
Python l3
Python l3Python l3
Python l3
 
Python list functions
Python list functionsPython list functions
Python list functions
 
List Manipulation in FME
List Manipulation in FMEList Manipulation in FME
List Manipulation in FME
 
Programming with Python - Week 3
Programming with Python - Week 3Programming with Python - Week 3
Programming with Python - Week 3
 
lists
listslists
lists
 
Introduction to Python programming Language
Introduction to Python programming LanguageIntroduction to Python programming Language
Introduction to Python programming Language
 
Data Structure lec#2
Data Structure lec#2Data Structure lec#2
Data Structure lec#2
 
Programming with Python - Week 2
Programming with Python - Week 2Programming with Python - Week 2
Programming with Python - Week 2
 
Intro to Lists
Intro to ListsIntro to Lists
Intro to Lists
 
The awesome algorithm
The awesome algorithmThe awesome algorithm
The awesome algorithm
 
Java Tutorial Lab 7
Java Tutorial Lab 7Java Tutorial Lab 7
Java Tutorial Lab 7
 

Viewers also liked

Array in c language
Array in c language Array in c language
Array in c language umesh patil
 
Data mining maximumlikelihood
Data mining maximumlikelihoodData mining maximumlikelihood
Data mining maximumlikelihoodHarry Potter
 
Jquery Preparation
Jquery PreparationJquery Preparation
Jquery Preparationumesh patil
 
OAuth2 Authentication
OAuth2 AuthenticationOAuth2 Authentication
OAuth2 AuthenticationIsmael Costa
 
Ccna security
Ccna security Ccna security
Ccna security umesh patil
 

Viewers also liked (7)

Array in c language
Array in c language Array in c language
Array in c language
 
Reflection
ReflectionReflection
Reflection
 
Data mining maximumlikelihood
Data mining maximumlikelihoodData mining maximumlikelihood
Data mining maximumlikelihood
 
Jquery Preparation
Jquery PreparationJquery Preparation
Jquery Preparation
 
OAuth2 Authentication
OAuth2 AuthenticationOAuth2 Authentication
OAuth2 Authentication
 
Mule db
Mule dbMule db
Mule db
 
Ccna security
Ccna security Ccna security
Ccna security
 

Similar to List and iterator

Java class 5
Java class 5Java class 5
Java class 5Edureka!
 
MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptxASRPANDEY
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptxSoniaKapoor56
 
List , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonList , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonchanna basava
 
Java10 Collections and Information
Java10 Collections and InformationJava10 Collections and Information
Java10 Collections and InformationSoftNutx
 
A2003822018_21789_17_2018_09. ArrayList.ppt
A2003822018_21789_17_2018_09. ArrayList.pptA2003822018_21789_17_2018_09. ArrayList.ppt
A2003822018_21789_17_2018_09. ArrayList.pptRithwikRanjan
 
L11 array list
L11 array listL11 array list
L11 array listteach4uin
 
ArrayList class and useful methods.pptx
ArrayList class and useful methods.pptxArrayList class and useful methods.pptx
ArrayList class and useful methods.pptxAbid523408
 
lecture 02.2.ppt
lecture 02.2.pptlecture 02.2.ppt
lecture 02.2.pptNathanielAdika
 
Collection Framework-1.pptx
Collection Framework-1.pptxCollection Framework-1.pptx
Collection Framework-1.pptxSarthakSrivastava70
 
Unit 1 array based implementation
Unit 1  array based implementationUnit 1  array based implementation
Unit 1 array based implementationLavanyaJ28
 
Python programming
Python programmingPython programming
Python programmingsirikeshava
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets Hitesh-Java
 

Similar to List and iterator (20)

STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
STRINGS IN JAVA
 
Java class 5
Java class 5Java class 5
Java class 5
 
MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptx
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
 
tupple.pptx
tupple.pptxtupple.pptx
tupple.pptx
 
List , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonList , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in python
 
Java10 Collections and Information
Java10 Collections and InformationJava10 Collections and Information
Java10 Collections and Information
 
A2003822018_21789_17_2018_09. ArrayList.ppt
A2003822018_21789_17_2018_09. ArrayList.pptA2003822018_21789_17_2018_09. ArrayList.ppt
A2003822018_21789_17_2018_09. ArrayList.ppt
 
javacollections.pdf
javacollections.pdfjavacollections.pdf
javacollections.pdf
 
L11 array list
L11 array listL11 array list
L11 array list
 
F# array searching
F#  array searchingF#  array searching
F# array searching
 
Lists
ListsLists
Lists
 
Collections Training
Collections TrainingCollections Training
Collections Training
 
ArrayList class and useful methods.pptx
ArrayList class and useful methods.pptxArrayList class and useful methods.pptx
ArrayList class and useful methods.pptx
 
lecture 02.2.ppt
lecture 02.2.pptlecture 02.2.ppt
lecture 02.2.ppt
 
Collection Framework-1.pptx
Collection Framework-1.pptxCollection Framework-1.pptx
Collection Framework-1.pptx
 
Unit 1 array based implementation
Unit 1  array based implementationUnit 1  array based implementation
Unit 1 array based implementation
 
Python programming
Python programmingPython programming
Python programming
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
 

More from Harry Potter

How to build a rest api.pptx
How to build a rest api.pptxHow to build a rest api.pptx
How to build a rest api.pptxHarry Potter
 
Business analytics and data mining
Business analytics and data miningBusiness analytics and data mining
Business analytics and data miningHarry Potter
 
Big picture of data mining
Big picture of data miningBig picture of data mining
Big picture of data miningHarry Potter
 
Data mining and knowledge discovery
Data mining and knowledge discoveryData mining and knowledge discovery
Data mining and knowledge discoveryHarry Potter
 
Directory based cache coherence
Directory based cache coherenceDirectory based cache coherence
Directory based cache coherenceHarry Potter
 
How analysis services caching works
How analysis services caching worksHow analysis services caching works
How analysis services caching worksHarry Potter
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsHarry Potter
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cacheHarry Potter
 
Smm & caching
Smm & cachingSmm & caching
Smm & cachingHarry Potter
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsHarry Potter
 
Abstract data types
Abstract data typesAbstract data types
Abstract data typesHarry Potter
 
Abstraction file
Abstraction fileAbstraction file
Abstraction fileHarry Potter
 
Object model
Object modelObject model
Object modelHarry Potter
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with javaHarry Potter
 
Encapsulation anonymous class
Encapsulation anonymous classEncapsulation anonymous class
Encapsulation anonymous classHarry Potter
 
Abstract class
Abstract classAbstract class
Abstract classHarry Potter
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysisHarry Potter
 
Rest api to integrate with your site
Rest api to integrate with your siteRest api to integrate with your site
Rest api to integrate with your siteHarry Potter
 

More from Harry Potter (20)

How to build a rest api.pptx
How to build a rest api.pptxHow to build a rest api.pptx
How to build a rest api.pptx
 
Business analytics and data mining
Business analytics and data miningBusiness analytics and data mining
Business analytics and data mining
 
Big picture of data mining
Big picture of data miningBig picture of data mining
Big picture of data mining
 
Data mining and knowledge discovery
Data mining and knowledge discoveryData mining and knowledge discovery
Data mining and knowledge discovery
 
Cache recap
Cache recapCache recap
Cache recap
 
Directory based cache coherence
Directory based cache coherenceDirectory based cache coherence
Directory based cache coherence
 
How analysis services caching works
How analysis services caching worksHow analysis services caching works
How analysis services caching works
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cache
 
Smm & caching
Smm & cachingSmm & caching
Smm & caching
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Abstraction file
Abstraction fileAbstraction file
Abstraction file
 
Object model
Object modelObject model
Object model
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
 
Encapsulation anonymous class
Encapsulation anonymous classEncapsulation anonymous class
Encapsulation anonymous class
 
Abstract class
Abstract classAbstract class
Abstract class
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
 
Api crash
Api crashApi crash
Api crash
 
Rest api to integrate with your site
Rest api to integrate with your siteRest api to integrate with your site
Rest api to integrate with your site
 

Recently uploaded

Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 

Recently uploaded (20)

Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 

List and iterator

  • 2. List Interface • Java has 3 classes which implement the List Interface - LinkedList, ArrayList and Vector. • How do you use the ArrayList in your program? • import java.util.* • How to create a List object? • List lst = new ArrayList(); • Can we do this? Why? • List lst = new List();
  • 3. • How to output the List object? • With the List object, we don’t need to use loop structure to print out each element, simply output the List object. Only the output will be surrounded by square brackets. • Name some of the List methods. • boolean isEmpty() • int size() • Object set(int index, Object o) • void add(int index, Object o) • boolean add(Object o) • Iterator<E> iterator()
  • 4. • Do we need to cast the element retrieved from a list object? • Yes, unless the list object was created using type parameters, meaning? • List doubleList = new ArrayList(); • /* fill in the Arraylist with some Double objects */ • Double aDouble = doubleList.get(0); => ok? • List<Double> doubleList = new ArrayList<Double>();
  • 5. List Interface • List interface. What is an interface? P135 1) All methods in the interface are both public and abstract. 2) Any class implementing the interface has to implement every method, otherwise… • More rule on p139.
  • 6. Iterator • What is Iteration? • Iteration is a continual repeating of something. • What java structure fits this description? • Loops are iteration structure • What is an iterator? • An iterator’a sole purpose is to traverse a collection, one element at a time. • Is Iterator a class? • NO, it is an interface.
  • 7. • What are the 3 methods of the Iterator? • boolean hasNext(); E next(); void remove() • How to use a generic iterator? • List<String> list = new ArrayList<String>(); <code to initialize list with strings> Iterator<String> itr = list.iterator(); while(itr.hasNext()) System.out.println(itr.next()) • What is above while loop equivalent to? • for-each loop
  • 8. practice • Write down the answers on the paper. • Write a generic List object of Integer. • Get an iterator from the List object. • Loop through the list and if the number is not mutiples of 3, remove it.
  • 9. What is wrong with the codes? Iterator<someType) itr = list.iterator(); while(true) System.out.println(itr.next()); Iterator<someType) itr = list.iterator(); someType ob= itr.next(); itr.remove(); itr.remove();
  • 10. • What is the different to use iterator from for- each loop • Use a for-each loop for accessing and modifying objects in a list. Use an iterator for removal of objects.
  • 11. Homework • Read Barron’s chapter 7 and BPJ lesson 40 about recursion. Write down any notes that you think are important. They can be in any form like questions and answers, or simply questions which you don’t understand. Everyone has to submit at least 25 notes or remarks.