Skip to content
Related Articles

Related Articles

Scala Iterator isTraversableAgain() method with example
  • Last Updated : 28 May, 2019

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 :




// 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)
  
    }
Output:
false

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




// 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)
  
    }
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
Recommended Articles
Page :