stream().map(i -> "?")
时间: 2024-05-15 16:15:19 浏览: 80
This is a Java code snippet that uses the `map()` method to transform each element of a `Stream` object into a string consisting of a single question mark (`?`).
Here is an example usage of this code:
```
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
List<String> questionMarks = numbers.stream().map(i -> "?").collect(Collectors.toList());
System.out.println(questionMarks); // Output: ["?", "?", "?", "?", "?"]
```
In this example, the `map()` method is applied to a `Stream` of integers (`numbers`) to transform each integer into a string consisting of a single question mark. The resulting `Stream` of strings is then collected into a `List` using the `collect()` method. Finally, the contents of the `List` are printed to the console.
阅读全文