티스토리 뷰

@FunctionalInterface
public interface Supplier<T> {
	T get(); // input 없이 return 값만 가지는 함수
}
package com.fastcampus.functionalprogramming.chapter5;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;

public class Chapter5Section4 {
	public static void main(String[] args) {
		// 1.
		printRandomDoubles(Math::random ,5);
		
		// 2.
		List<String> names = new ArrayList<>();
		names.add("Bob");
		names.add("Charlie");
		names.add("Alice");
		System.out.println(names);
		
		Collections.sort(names, String::compareTo);
		System.out.println(names);
	}
	
	public static void printRandomDoubles(Supplier<Double> randomSupplier, int count) {
		for (int i = 0; i < count; i++) {
			System.out.println(randomSupplier.get());
		}
	}
}

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함