流builder()返回流的构建器。
用法:
static <T> Stream.Builder<T> builder() where, T is the type of elements.
返回值:流构建器。
示例1:
// Java code for Stream builder()
import java.util.*;
import java.util.stream.Stream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Using Stream builder()
Stream.Builder<String> builder = Stream.builder();
// Adding elements in the stream of Strings
Stream<String> stream = builder.add("Geeks").build();
// Displaying the elements in the stream
stream.forEach(System.out::println);
}
}
输出:
Geeks
示例2:
// Java code for Stream builder()
import java.util.*;
import java.util.stream.Stream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Using Stream builder()
Stream.Builder<String> builder = Stream.builder();
// Adding elements in the stream of Strings
Stream<String> stream = builder.add("Geeks")
.add("for")
.add("Geeks")
.add("GeeksQuiz")
.build();
// Displaying the elements in the stream
stream.forEach(System.out::println);
}
}
输出:
Geeks for Geeks GeeksQuiz
示例3:
// Java code for Stream builder()
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.Collectors;
class GFG {
// Driver code
public static void main(String[] args)
{
// Using Stream builder()
Stream.Builder<String> builder = Stream.builder();
// Adding elements in the stream of Strings
Stream<String> stream = builder.add("GEEKS")
.add("for")
.add("Geeks")
.add("GeEKSQuiz")
.build();
// Converting elements to Lower Case
// and storing them in List list
List<String> list = stream.map(String::toLowerCase)
.collect(Collectors.toList());
// Displaying the elements in list
System.out.println(list);
}
}
输出:
[geeks, for, geeks, geeksquiz]
相关用法
- Java Stream.Builder add()用法及代码示例
- Java Stream.Builder accept()用法及代码示例
- Java DoubleStream builder()用法及代码示例
- Java DoubleStream.Builder add(double t)用法及代码示例
- Java IntStream.Builder build()用法及代码示例
- Java Locale.Builder setRegion()用法及代码示例
- Java Locale.Builder setLanguageTag()用法及代码示例
- Java Locale.Builder setUnicodeLocaleKeyword()用法及代码示例
- Java Locale.Builder setExtension()用法及代码示例
- Java Locale.Builder setLanguage()用法及代码示例
- Java Locale.Builder build()用法及代码示例
- Java Locale.Builder clearExtensions()用法及代码示例
- Java Locale.Builder clear()用法及代码示例
- Java Locale.Builder setScript()用法及代码示例
注:本文由纯净天空筛选整理自Sahil_Bansall大神的英文原创作品 Stream builder() in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。