Java Collection : Iterable

Oleh : Reza Ervani

بسم الله الرحمن الرحيم

Rujukan :

http://tutorials.jenkov.com/java-collections/iterable.html

Interface Iterable  (java.lang.Iterable) adalah satu dari interface root pada class Java collection. Interface Collection melebarkan/extends  Iterable, jadi semua subtipe Collection juga mengimplementasikan interface Iterable.

Suatu class yang mengimplementasikan Iterable dapat diguankan dengan new for-loop. Berikut contohnya :

[code language=”java”]

List list = new ArrayList();

for(Object o : list){
//do something o;
}

[/code]

Interface Iterable hanya memiliki satu metode :

[code language=”java”]

public interface Iterable<T> {
public Iterator<T> iterator();
}

[/code]

Bagaimana kita mengimplementasikan interface Iterable ini sehingga kita dapat menggunakannya dengan new for-loop akan dijelaskan pada bagian Tutorial Java Generic di bagian Mengimplementasikan Interface Iterable, insya Allah

(reza@rumahilmu.or.id)

About Reza Ervani 425 Articles
Adalah pendiri programming.rezaervani.com -

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.