标签:
public class MethodReferenceDemo1 {
@FunctionalInterface
interface StringListFormatter {
String format(String delimiter, List<String> list);
}
public static void formatAndPrint(StringListFormatter formatter, String delimiter, List<String> list) {
String formatted = formatter.format(delimiter, list);
System.out.println(formatted);
}
public static void main(String[] args) {
List<String> names = Arrays.asList("Don", "King", "Kong");
formatAndPrint(String::join, ", ", names);
}
}
使用Java 8 API,根据传递的分隔符,连接list中所有的元素
标签:
原文地址:http://www.cnblogs.com/IcanFixIt/p/4253296.html