Scala Iterator sameElements() method with example
The sameElements() method belongs to the concrete value members of the class iterator of Scala. It checks whether the two stated iterators produce the identical elements in alike order or not. This method won’t terminate for infinite iterators.
-
Method Definition:
def sameElements(that: Iterator[_]): Boolean
Where, that is the another iterator stated.
-
Return Type:
It returns true if both the iterators produce identical elements in the same order else it returns false.
Example-1:
// Scala program of sameElements() // method // Creating object object GfG { // Main method def main(args : Array[String]) { // Declaring an iterator val iter = Iterator( 3 , 4 , 5 , 6 , 7 ) // Declaring an another iterator val iter 1 = Iterator( 3 , 4 , 5 , 6 , 7 ) // Applying sameElements method val result = iter.sameElements(iter 1 ) // Displays output println(result) } } |
true
Here, both the stated iterators are identical so, sameElements method returns true.
Example :
// Scala program of sameElements() // method // Creating object object GfG { // Main method def main(args : Array[String]) { // Declaring an iterator val iter = Iterator( 3 , 4 , 5 , 6 , 7 ) // Declaring an another iterator val iter 1 = Iterator( 3 , 4 , 5 , 9 , 7 ) // Applying sameElements method val result = iter.sameElements(iter 1 ) // Displays output println(result) } } |
false
Here, both the stated iterators are not identical so, sameElements method returns false.
Recommended Posts:
- Scala Iterator take() method with example
- Scala Iterator map() method with example
- Scala Iterator sum() method with example
- Scala Iterator zip() method with example
- Scala Iterator max() method with example
- Scala Map iterator method with example
- Scala Iterator min() method with example
- Scala Iterator seq() method with example
- Scala Iterator next() method with example
- Scala Iterator product() method with example
- Scala Iterator slice() method with example
- Scala Iterator nonEmpty() method with example
- Scala Iterator hasDefiniteSize() method with example
- Scala Iterator duplicate() method with example
- Scala Iterator mkString() method with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.