Scala Iterator isTraversableAgain() method with example

The isTraversableAgain() method belongs to the concrete value member of the class iterator in Scala. It checks whether the iterator can be repeatedly traversed or not.

  • Method Definition:

    def isTraversableAgain: Boolean
    
  • Return Type:
    It returns true if the stated iterator can be traversed repeatedly and if it cannot be traversed repeatedly then it returns false.

Example :

filter_none

edit
close

play_arrow

link
brightness_4
code

// Scala program of isTraversableAgain()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Declaring an iterator
        val iter = Iterator(3, 1, 7, 9, 15)
          
        // Applying isTraversableAgain 
        // method 
        val result = iter.isTraversableAgain
          
        // Displays output
        println(result)
  
    }

chevron_right


Output:

false

Here, the iterator cannot be traversed repeatedly so, it returns false.
Example :

filter_none

edit
close

play_arrow

link
brightness_4
code

// Scala program of isTraversableAgain()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Declaring an empty iterator
        val iter = Iterator()
          
        // Applying isTraversableAgain 
        // method 
        val result = iter.isTraversableAgain
          
        // Displays output
        println(result)
  
    }

chevron_right


Output:

false

Here, we have declared an empty iterator and even that cannot be traversed repeatedly so, the method returns false.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.