0% found this document useful (0 votes)
1 views1 page

Iterable Java Handwritten Notes

Iterable is a Java interface that allows for the traversal of objects, primarily used with collections. It enables the for-each loop and requires the implementation of the iterator() method. Key points include its role as the root interface of collections and its focus on sequential access.

Uploaded by

aaradhyassanjay
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views1 page

Iterable Java Handwritten Notes

Iterable is a Java interface that allows for the traversal of objects, primarily used with collections. It enables the for-each loop and requires the implementation of the iterator() method. Key points include its role as the root interface of collections and its focus on sequential access.

Uploaded by

aaradhyassanjay
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ITERABLE IN JAVA

Definition: Iterable is an interface in Java that allows objects to be traversed.

Package: [Link]

Syntax: public interface Iterable<T>

Main Method: Iterator<T> iterator()

Purpose:

- Enables for-each loop

- Used to traverse collections

Example (For-each loop):


List<String> names = new ArrayList<>();
[Link]("Sanjay");
[Link]("Arun");

for(String name : names){


[Link](name);
}

Iterator Example:
Iterator<Integer> it = [Link]();
while([Link]()){
[Link]([Link]());
}

Important Points:

- Root interface of collections

- Only one method: iterator()

- Used for sequential access

You might also like