Skip to content
Reference > Classes

Iterator

Definition

Iterator var = .... ;

Extends

Extended By

None

Method Summary

Owner Name Return Type Description
Object getClassName() String Returns the string name of this object's class type.
Iterator hasNext() Object Returns "true" if there are more elements remaining in the iterator, i.e when next() returns an element, and "false" if not.
Iterator next() Object Returns the next value from the iterator
Object toJson() String Returns a string of a json representation of this object.

Method Definitions


getClassName()

String Object::getClassName()

Description

Returns the string name of this object's class type.

Example 17

1
2
3
4
5
Set s = new Set("a", "b", "c");
Iterator i = s.iterator();
i.getClassName();

// i.getClassName() = Iterator

hasNext()

Object Iterator::hasNext()

Description

Returns "true" if there are more elements remaining in the iterator, i.e when next() returns an element, and "false" if not.

Example 1

1
2
3
4
5
6
7
8
Set s = new Set(1, 2, 3);
Iterator i = s.iterator();
int setsize = 0;
while(i.hasNext()) { 
    i.next();
    setsize++;
}
// setsize = 3

Where sets don't natively have a size() method, iterators can be used instead to determine the size of a set.


next()

Object Iterator::next()

Description

Returns the next value from the iterator

Example 1

1
2
3
4
5
6
Set s = new Set(1, 2, 3);
Iterator i = s.iterator();
string nextvalue = i.next(); //iterate to the next element

// nextvalue = 1
// i.next() = 2

toJson()

String Object::toJson()

Description

Returns a string of a json representation of this object.

Example 17

1
2
3
4
5
Set s = new Set("a", "b", "c");
Iterator i = s.iterator();
i.toJson();

// i.toJson() = "java.util.LinkedHashMap$LinkedKeyIterator@1280851e"