Iterator
  • An iterator isn’t a collection; instead, it gives you a way to access the elements in a collection, one by one
  • Not able to call the same call a second time, because the iterator has been exhausted
  • object Demo
    {
      def main(args : Array[String])
      {
        var a = Iterator(4, 2, 1, 3)
    
        while (a.hasNext)
          println(a.next());
      }
    }
    		
    object Demo
    {
      def main(args : Array[String])
      {
        var a = Iterator(4, 2, 1, 3)
    
        println("Min: "+a.min) // 1
        println("Max: "+a.max) // empty
      }
    }
    		
    object Demo
    {
      def main(args : Array[String])
      {
        var a = Iterator(4, 2, 1, 3)
    
        var b = a.toArray;
    
        for(e <- b)
          println(e)
      }
    }
    		
    Reference
  • Iterator