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

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

Revolucion de la comunicacion final power point
Revolucion de la comunicacion final power pointRevolucion de la comunicacion final power point
Revolucion de la comunicacion final power pointYasmehira
 
三十六道八卦阵 — 本能阵
三十六道八卦阵 — 本能阵三十六道八卦阵 — 本能阵
三十六道八卦阵 — 本能阵Baishen Cao
 
IIMBx OM101.1x Certificate _ edX
IIMBx OM101.1x Certificate _ edXIIMBx OM101.1x Certificate _ edX
IIMBx OM101.1x Certificate _ edXDarshan Soni
 
Virus y vacunas
Virus y vacunasVirus y vacunas
Virus y vacunasRONALDYMAR
 
Quince insects A Lecture To ToT trainees ( FFS) By Mr. Allah Dad Khan Pro...
Quince insects A Lecture To ToT trainees ( FFS)  By  Mr. Allah Dad Khan  Pro...Quince insects A Lecture To ToT trainees ( FFS)  By  Mr. Allah Dad Khan  Pro...
Quince insects A Lecture To ToT trainees ( FFS) By Mr. Allah Dad Khan Pro...Mr.Allah Dad Khan
 
Hereka widget presentation
Hereka widget presentationHereka widget presentation
Hereka widget presentationBarcampCameroon
 
Relational database
Relational  databaseRelational  database
Relational databaseamkrisha
 
Desarrollo de la guia 2 power point
Desarrollo de la guia 2 power pointDesarrollo de la guia 2 power point
Desarrollo de la guia 2 power pointwalcalo32
 
Chi square Test Using SPSS
Chi square Test Using SPSSChi square Test Using SPSS
Chi square Test Using SPSSDr Athar Khan
 
Aktywne Słuchanie & Efektywna Komunikacja (WUD Silesia 2014)
Aktywne Słuchanie & Efektywna Komunikacja (WUD Silesia 2014)Aktywne Słuchanie & Efektywna Komunikacja (WUD Silesia 2014)
Aktywne Słuchanie & Efektywna Komunikacja (WUD Silesia 2014)Bartosz Mozyrko
 
Predictive modeling healthcare
Predictive modeling healthcarePredictive modeling healthcare
Predictive modeling healthcareTaposh Roy
 
Metode Studi Kasus-Teaching Case
Metode Studi Kasus-Teaching CaseMetode Studi Kasus-Teaching Case
Metode Studi Kasus-Teaching CaseAsropi, Dr.
 
Tableau Dashboard Design Best Practices
Tableau Dashboard Design Best Practices Tableau Dashboard Design Best Practices
Tableau Dashboard Design Best Practices Senturus
 

Viewers also liked (18)

Revolucion de la comunicacion final power point
Revolucion de la comunicacion final power pointRevolucion de la comunicacion final power point
Revolucion de la comunicacion final power point
 
三十六道八卦阵 — 本能阵
三十六道八卦阵 — 本能阵三十六道八卦阵 — 本能阵
三十六道八卦阵 — 本能阵
 
Tarea 5
Tarea 5Tarea 5
Tarea 5
 
IIMBx OM101.1x Certificate _ edX
IIMBx OM101.1x Certificate _ edXIIMBx OM101.1x Certificate _ edX
IIMBx OM101.1x Certificate _ edX
 
Virus y vacunas
Virus y vacunasVirus y vacunas
Virus y vacunas
 
Quince insects A Lecture To ToT trainees ( FFS) By Mr. Allah Dad Khan Pro...
Quince insects A Lecture To ToT trainees ( FFS)  By  Mr. Allah Dad Khan  Pro...Quince insects A Lecture To ToT trainees ( FFS)  By  Mr. Allah Dad Khan  Pro...
Quince insects A Lecture To ToT trainees ( FFS) By Mr. Allah Dad Khan Pro...
 
Text Analytics
Text AnalyticsText Analytics
Text Analytics
 
Data Science Hands-On
Data Science Hands-OnData Science Hands-On
Data Science Hands-On
 
Hereka widget presentation
Hereka widget presentationHereka widget presentation
Hereka widget presentation
 
Joré Systems
Joré SystemsJoré Systems
Joré Systems
 
Relational database
Relational  databaseRelational  database
Relational database
 
Desarrollo de la guia 2 power point
Desarrollo de la guia 2 power pointDesarrollo de la guia 2 power point
Desarrollo de la guia 2 power point
 
Chi square Test Using SPSS
Chi square Test Using SPSSChi square Test Using SPSS
Chi square Test Using SPSS
 
Aktywne Słuchanie & Efektywna Komunikacja (WUD Silesia 2014)
Aktywne Słuchanie & Efektywna Komunikacja (WUD Silesia 2014)Aktywne Słuchanie & Efektywna Komunikacja (WUD Silesia 2014)
Aktywne Słuchanie & Efektywna Komunikacja (WUD Silesia 2014)
 
Spotkania, ach spotkania, czyli co zrobić, by dyskusja nie zamieniła się w kł...
Spotkania, ach spotkania, czyli co zrobić, by dyskusja nie zamieniła się w kł...Spotkania, ach spotkania, czyli co zrobić, by dyskusja nie zamieniła się w kł...
Spotkania, ach spotkania, czyli co zrobić, by dyskusja nie zamieniła się w kł...
 
Predictive modeling healthcare
Predictive modeling healthcarePredictive modeling healthcare
Predictive modeling healthcare
 
Metode Studi Kasus-Teaching Case
Metode Studi Kasus-Teaching CaseMetode Studi Kasus-Teaching Case
Metode Studi Kasus-Teaching Case
 
Tableau Dashboard Design Best Practices
Tableau Dashboard Design Best Practices Tableau Dashboard Design Best Practices
Tableau Dashboard Design Best Practices
 

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
 
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 Tony Nguyen

Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysisTony Nguyen
 
Directory based cache coherence
Directory based cache coherenceDirectory based cache coherence
Directory based cache coherenceTony Nguyen
 
Business analytics and data mining
Business analytics and data miningBusiness analytics and data mining
Business analytics and data miningTony Nguyen
 
Big picture of data mining
Big picture of data miningBig picture of data mining
Big picture of data miningTony Nguyen
 
Data mining and knowledge discovery
Data mining and knowledge discoveryData mining and knowledge discovery
Data mining and knowledge discoveryTony Nguyen
 
How analysis services caching works
How analysis services caching worksHow analysis services caching works
How analysis services caching worksTony Nguyen
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cacheTony Nguyen
 
Abstract data types
Abstract data typesAbstract data types
Abstract data typesTony Nguyen
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsTony Nguyen
 
Abstraction file
Abstraction fileAbstraction file
Abstraction fileTony Nguyen
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with javaTony Nguyen
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsTony Nguyen
 
Object oriented programming-with_java
Object oriented programming-with_javaObject oriented programming-with_java
Object oriented programming-with_javaTony Nguyen
 
Cobol, lisp, and python
Cobol, lisp, and pythonCobol, lisp, and python
Cobol, lisp, and pythonTony Nguyen
 
Extending burp with python
Extending burp with pythonExtending burp with python
Extending burp with pythonTony Nguyen
 

More from Tony Nguyen (20)

Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
 
Directory based cache coherence
Directory based cache coherenceDirectory based cache coherence
Directory based cache coherence
 
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
 
How analysis services caching works
How analysis services caching worksHow analysis services caching works
How analysis services caching works
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cache
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
 
Abstract class
Abstract classAbstract class
Abstract class
 
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
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Inheritance
InheritanceInheritance
Inheritance
 
Object oriented programming-with_java
Object oriented programming-with_javaObject oriented programming-with_java
Object oriented programming-with_java
 
Cobol, lisp, and python
Cobol, lisp, and pythonCobol, lisp, and python
Cobol, lisp, and python
 
Extending burp with python
Extending burp with pythonExtending burp with python
Extending burp with python
 
Api crash
Api crashApi crash
Api crash
 

Recently uploaded

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
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
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
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
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"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
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
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
 
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
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 

Recently uploaded (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
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
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
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
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"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
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
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
 
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
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 

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.