Skip to content

Instantly share code, notes, and snippets.

@zhuifeng1017
Last active November 1, 2018 02:23
Show Gist options
  • Save zhuifeng1017/3a8161086959b31598c66a1d5995c308 to your computer and use it in GitHub Desktop.
Save zhuifeng1017/3a8161086959b31598c66a1d5995c308 to your computer and use it in GitHub Desktop.
Java8 stream filter
//filter eg
String strs[] = new String[]{"1","2", "0", "33", "3", "4","abc"};
List list = Arrays.stream(strs).filter(b -> b.length()<3 ).sorted().collect(Collectors.toList());
list.stream().forEach( System.out::println);
System.out.println("------------------");
// map eg
List list2 = Arrays.stream(strs).map(v->v.substring(0,1)).sorted().collect(Collectors.toList());
list2.stream().forEach( System.out::println);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment