- Design Patterns and Best Practices in Java
- Kamalmeet Singh Adrian Ianculescu LUCIAN PAUL TORJE
- 122字
- 2021-06-25 20:52:38
Applicability and examples
Iterators are popular in most programming languages these days. It is probably most widely used in Java, along with the collections package. It is also implemented at the language level when a collection is traversed with the following loop construction:
for (String item : strCollection)
System.out.println(item);
The iterator pattern can be implemented using the generics mechanism. This way, we can make sure we can avoid runtime errors generated by forced castings.
Good practice when implementing new containers and iterators in Java is to implement the existing java.util.Iterator<E> and java.util.Collection<E> classes. When we need aggregators with specific behaviors, we should also consider extending one of the classes that were implemented in the java.collection package instead of creating a new one.
- Java EE 6 企業(yè)級應(yīng)用開發(fā)教程
- Python自動化運維快速入門
- JavaScript+Vue+React全程實例
- 微信小程序項目開發(fā)實戰(zhàn)
- Building RESTful Python Web Services
- Learning Concurrent Programming in Scala
- 打開Go語言之門:入門、實戰(zhàn)與進(jìn)階
- iPhone應(yīng)用開發(fā)從入門到精通
- Java零基礎(chǔ)實戰(zhàn)
- JavaScript腳本特效編程給力起飛
- Flask Web開發(fā):基于Python的Web應(yīng)用開發(fā)實戰(zhàn)(第2版)
- Java EE架構(gòu)設(shè)計與開發(fā)實踐
- 現(xiàn)代JavaScript編程:經(jīng)典范例與實踐技巧
- Python量子計算實踐:基于Qiskit和IBM Quantum Experience平臺
- Java EE框架開發(fā)技術(shù)與案例教程