http://www.technicalpage.net/search/label/SQL

forEach

 forEach

package test;

 

import java.util.Arrays;

import java.util.List;

import java.util.function.Consumer;

 

public class forEach {

 

       public static void main(String[] args) {

 

             List<String> list_names = Arrays.asList("John", "Tina", "Mike");

              

            //Anonymous class

             list_names.forEach(new Consumer<String>() {

 

                    @Override

                    public void accept(String str) {

                           System.out.println(str);

                           //System.out.println("The names is : " + str);

                    }

             });

       }

}

Output:

John
Tina
Mike
 

-------------------------------------------------------------

if

System.out.println("The names is : " + str);

is used:

Output:

The names is : John
The names is : Tina
The names is : Mike

No comments:

Post a Comment