--- size digital call delay arrangement method (Supplier)

package tompeixun.demo05;

import java.util.Arrays;
import java.util.function.Supplier;

//通过Supplier<T>接口求数组最大值
public class Demo02 {
    public static int getMax(Supplier<Integer> supplier) {
        return supplier.get();
    }

    public static void main(String[] args) {
        int[] array = {2, 5, 1, 6, 0};
        int maxValue = getMax(new Supplier<Integer>() {
            @Override
            public Integer get() {
                int max = Array [0]; // assumed that the first array element is maximum
                 // then traversing the array, if the value is greater than max, max is assigned the value of the put
                 // the cycle again down, max stored is the maximum value in the array 
                for ( int Item: array 
                        ) { 
                    IF (Item> max) { 
                        max = Item; 
                    } 
                } 
                return max; 
            } 
        }); 
        System.out.println (of Arrays.toString (array)); 
        the System. Out.println ( "anonymous inner classes seeking the maximum array:" + maxValue); 


        int maxValue2 getMax = (() ->{
                     Int max = Array [0]; // first element of the array is the maximum value assumed
                     @ then begins to traverse the array, if the value is greater than max, max is assigned the value of the put
                     // the cycle again down, max save is the maximum value in the array 
                    for ( int Item: array 
                            ) { 
                        IF (Item> max) { 
                            max = Item; 
                        } 
                    } 
                    return max; 
                } 
        );

 

Guess you like

Origin www.cnblogs.com/GooKiki/p/11429110.html