Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

foreach: A Collection Method

Sumit Rawal answered on May 23, 2023 Popularity 5/10 Helpfulness 1/10

Contents


More Related Answers

  • java foreach list
  • foreach() java
  • iterate through collection java
  • java foreach method
  • iterate through entries of collection<t> java
  • Java forEach() Method
  • Laravel - foreach on collection
  • loop over collections or create new collection
  • Iterating Through a Collection#

  • foreach: A Collection Method

    0

    Introduction

    Syntax

    Introduction

    As this chapter deals with collections, it is important to know how to print the elements in a collection.

    We cannot simply use println or print as they are used to print single values and collections are a collection of values. For this reason, Scala provides the foreach method. This method can be used by every instance of every class in the collection library.

    Syntax

    The foreach method is called on a collection of any type and takes a single argument. The argument must be a function/method that will be applied to each individual element of the collection.


    For printing the elements of a collection, we would need to apply the println or print method to each element. 

    Popularity 5/10 Helpfulness 1/10 Language scala
    Source: Grepper
    Tags: scala
    Link to this answer
    Share Copy Link
    Contributed on May 23 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.