将数组转化为list:


Arrays.asList(atp);


lambda实现数据过滤, 并行操作, 循环输出案例:

1.需求:打印输出已经排好序的字符串数组中长度大于20 ,并且为其添加hello ;

    数据源:


String[] players = {"Rafael Nadal", "Novak Djokovic", "Stanislas Wawrinka", "David Ferrer", "Roger Federer", "Andy Murray", "Tomas Berdych", "Juan Martin Del Potro", "Richard Gasquet", "John Isner"};


  排序:


Arrays.sort(players);


  转化为list操作: 


List<String> list=Arrays.asList(players);


  过滤长度大于20 ,并为其添加hello 输出:


list.stream().filter(a->a.length()>20).map(a->a+=" hello").forEach(player->System.out.println(player));


2.需求:对多个对象,按照年龄进行排序输出:

  数据源:(省略对象类 name ,age )


public static List<People> peopleList = new ArrayList<People>();


peopleList.add(new People("a",17)); peopleList.add(new People("b",16)); peopleList.add(new People("c",19)); peopleList.add(new People("d",15));


按照年龄排序:


Collections.sort(peopleList,(People a,People b)->a.getAge().compareTo(b.getAge())); peopleList.stream().forEach(a->System.out.println(a.getAge()));