本文整理了Java中java.util.stream.Collectors.toList()
方法的一些代码示例,展示了Collectors.toList()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collectors.toList()
方法的具体详情如下:
包路径:java.util.stream.Collectors
类名称:Collectors
方法名:toList
暂无
canonical example by Tabnine
public List<Integer> findDivisors(int number) {
return Stream.iterate(1, k -> ++k)
.limit(number)
.filter(k -> number % k == 0)
.collect(Collectors.toList());
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Re-create the given mime types as media types.
* @since 5.0
*/
public static List<MediaType> asMediaTypes(List<MimeType> mimeTypes) {
return mimeTypes.stream().map(MediaType::asMediaType).collect(Collectors.toList());
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Get all methods in the supplied {@link Class class} and its superclasses
* which are annotated with the supplied {@code annotationType} but
* which are not <em>shadowed</em> by methods overridden in subclasses.
* <p>Default methods on interfaces are also detected.
* @param clazz the class for which to retrieve the annotated methods
* @param annotationType the annotation type for which to search
* @return all annotated methods in the supplied class and its superclasses
* as well as annotated interface default methods
*/
private List<Method> getAnnotatedMethods(Class<?> clazz, Class<? extends Annotation> annotationType) {
return Arrays.stream(ReflectionUtils.getUniqueDeclaredMethods(clazz))
.filter(method -> AnnotatedElementUtils.hasAnnotation(method, annotationType))
.collect(Collectors.toList());
}
代码示例来源:origin: google/guava
@Override
List<? extends Entry<?, ?>> createAdversarialEntries(int power, CallsCounter counter) {
List<?> keys = createAdversarialObjects(power, counter);
List<?> values = createAdversarialObjects(power, counter);
return Streams.zip(keys.stream(), values.stream(), Maps::immutableEntry).collect(toList());
}
};
代码示例来源:origin: apache/incubator-dubbo
private <T> List<Invoker<T>> filterInvoker(List<Invoker<T>> invokers, Predicate<Invoker<T>> predicate) {
return invokers.stream()
.filter(predicate)
.collect(Collectors.toList());
}
代码示例来源:origin: apache/incubator-dubbo
private <T> List<Invoker<T>> filterInvoker(List<Invoker<T>> invokers, Predicate<Invoker<T>> predicate) {
return invokers.stream()
.filter(predicate)
.collect(Collectors.toList());
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Return all registered interceptors.
*/
protected List<Object> getInterceptors() {
return this.registrations.stream()
.sorted(INTERCEPTOR_ORDER_COMPARATOR)
.map(InterceptorRegistration::getInterceptor)
.collect(Collectors.toList());
}
代码示例来源:origin: apache/incubator-dubbo
public static List<URL> classifyUrls(List<URL> urls, Predicate<URL> predicate) {
return urls.stream().filter(predicate).collect(Collectors.toList());
}
代码示例来源:origin: apache/incubator-dubbo
public static List<URL> classifyUrls(List<URL> urls, Predicate<URL> predicate) {
return urls.stream().filter(predicate).collect(Collectors.toList());
}
代码示例来源:origin: spring-projects/spring-framework
@Nullable
private <T> T createSingleBean(Function<WebFluxConfigurer, T> factory, Class<T> beanType) {
List<T> result = this.delegates.stream().map(factory).filter(Objects::nonNull).collect(Collectors.toList());
if (result.isEmpty()) {
return null;
}
else if (result.size() == 1) {
return result.get(0);
}
else {
throw new IllegalStateException("More than one WebFluxConfigurer implements " +
beanType.getSimpleName() + " factory method.");
}
}
代码示例来源:origin: spring-projects/spring-framework
private List<SyncHandlerMethodArgumentResolver> initBinderResolvers(
ArgumentResolverConfigurer customResolvers, ReactiveAdapterRegistry reactiveRegistry,
ConfigurableApplicationContext context) {
return initResolvers(customResolvers, reactiveRegistry, context, false, Collections.emptyList()).stream()
.filter(resolver -> resolver instanceof SyncHandlerMethodArgumentResolver)
.map(resolver -> (SyncHandlerMethodArgumentResolver) resolver)
.collect(Collectors.toList());
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Collection<List<String>> values() {
return this.headers.getHeaderNames().stream()
.map(this.headers::get)
.collect(Collectors.toList());
}
代码示例来源:origin: spring-projects/spring-framework
private static void addBindValue(Map<String, Object> params, String key, List<?> values) {
if (!CollectionUtils.isEmpty(values)) {
values = values.stream()
.map(value -> value instanceof FormFieldPart ? ((FormFieldPart) value).value() : value)
.collect(Collectors.toList());
params.put(key, values.size() == 1 ? values.get(0) : values);
}
}
代码示例来源:origin: spring-projects/spring-framework
private List<byte[]> getDelimiterBytes(@Nullable MimeType mimeType) {
return this.delimitersCache.computeIfAbsent(getCharset(mimeType),
charset -> this.delimiters.stream()
.map(s -> s.getBytes(charset))
.collect(Collectors.toList()));
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Return the configured argument resolvers.
*/
public List<SyncHandlerMethodArgumentResolver> getResolvers() {
return this.delegate.getResolvers().stream()
.map(resolver -> (SyncHandlerMethodArgumentResolver) resolver)
.collect(Collectors.toList());
}
代码示例来源:origin: eclipse-vertx/vert.x
public synchronized List<T> handlers() {
return handlerMap.values().stream()
.flatMap(handlers -> handlers.list.stream())
.map(holder -> holder.handler)
.collect(Collectors.toList());
}
代码示例来源:origin: spring-projects/spring-framework
private void updateFilters() {
if (this.filters.isEmpty()) {
return;
}
List<WebFilter> filtersToUse = this.filters.stream()
.peek(filter -> {
if (filter instanceof ForwardedHeaderTransformer && this.forwardedHeaderTransformer == null) {
this.forwardedHeaderTransformer = (ForwardedHeaderTransformer) filter;
}
})
.filter(filter -> !(filter instanceof ForwardedHeaderTransformer))
.collect(Collectors.toList());
this.filters.clear();
this.filters.addAll(filtersToUse);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Parse the comma-separated string into a list of {@code MimeType} objects.
* @param mimeTypes the string to parse
* @return the list of mime types
* @throws InvalidMimeTypeException if the string cannot be parsed
*/
public static List<MimeType> parseMimeTypes(String mimeTypes) {
if (!StringUtils.hasLength(mimeTypes)) {
return Collections.emptyList();
}
return tokenize(mimeTypes).stream()
.map(MimeTypeUtils::parseMimeType).collect(Collectors.toList());
}
代码示例来源:origin: apache/incubator-druid
public List<PostAggregator> getPostAggregators()
{
return aggregations.stream()
.map(Aggregation::getPostAggregator)
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public void values(Handler<AsyncResult<List<V>>> asyncResultHandler) {
List<V> result = map.values().stream()
.filter(Holder::hasNotExpired)
.map(h -> h.value)
.collect(toList());
asyncResultHandler.handle(Future.succeededFuture(result));
}
内容来源于网络,如有侵权,请联系作者删除!