Skip to content
Related Articles

Related Articles

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

The hasDefiniteSize() method is a concrete value member of AbstractMap class. It checks whether the stated traversable collection is having a finite size or not.

  • Method Definition:

    def hasDefiniteSize: Boolean
    
  • Return Type:
    It returns true if the stated collection has finite size else returns false or if the iterator is empty it returns true otherwise returns false.

Example :




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


Output:

true

Here, the iterator is empty so, the hasDefiniteSize method returns true.
Example :




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


Output:

false

Here, the stated iterator is non-empty so, the method hasDefiniteSize returns false.




My Personal Notes arrow_drop_up
Recommended Articles
Page :