(String[] args)
| 8 | |
| 9 | public class CollectionIntoStream { |
| 10 | public static void main(String[] args) { |
| 11 | List<String> strings = |
| 12 | Stream.generate(new Rand.String(5)) |
| 13 | .limit(10) |
| 14 | .collect(Collectors.toList()); |
| 15 | strings.forEach(System.out::println); |
| 16 | // Convert to a Stream for many more options: |
| 17 | String result = strings.stream() |
| 18 | .map(String::toUpperCase) |
| 19 | .map(s -> s.substring(2)) |
| 20 | .reduce(":", (s1, s2) -> s1 + s2); |
| 21 | System.out.println(result); |
| 22 | } |
| 23 | } |
| 24 | /* Output: |
| 25 | btpen |