一.打印数组

String[] s = "fdsfsdfds".split("");     
Stream<String> str = Stream.of(s);
str.forEach(d->System.out.print(d + " "));//编译器可以自动推断d的类型
 //output: f d s f s d f d s 

二.方法引用

利用方法引用 上面的代码也可以被写成如下形式

str.forEach(System.out::print);//方法引用,System.out::print等价于x -> System.out.println(x)
//output: fdsfsdfds

 三. 接口

public class Text{
public static void main(String[] args)
{
Tests tsd = ()->"fdsadfsds"; //接口只能有一个函数
System.out.println(tsd.print());
//output: fdsadfsds
}
}
interface Tests{
public String print();
}

 

相关文章:

  • 2021-07-26
  • 2022-12-23
  • 2022-12-23
  • 2021-10-08
  • 2022-12-23
  • 2021-08-24
  • 2021-08-06
猜你喜欢
  • 2021-11-27
  • 2021-07-10
  • 2021-06-02
  • 2021-10-03
  • 2021-12-11
  • 2022-12-23
  • 2021-11-26
相关资源
相似解决方案