Tabnine Logo
Stream.collect
Code IndexAdd Tabnine to your IDE (free)

How to use
collect
method
in
java.util.stream.Stream

Best Java code snippets using java.util.stream.Stream.collect (Showing top 20 results out of 90,504)

Refine searchRefine arrow

  • Collectors.toList
  • Stream.map
  • List.stream
  • Collection.stream
  • Stream.filter
canonical example by Tabnine

private Double calculateAverageGrade(Map<String, List<Integer>> gradesList, String studentName)
  throws Exception {
 return Optional.ofNullable(gradesList.get(studentName))
   .map(list -> list.stream().collect(Collectors.averagingDouble(x -> x)))
   .orElseThrow(() -> new Exception("Student not found - " + studentName));
}
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());
}
canonical example by Tabnine

public void printFibonacciSequence(int length) {
 System.out.println(
   Stream.iterate(new long[] {0, 1}, pair -> new long[] {pair[1], pair[0] + pair[1]})
     .limit(length)
     .map(pair -> Long.toString(pair[1]))
     .collect(Collectors.joining(", ")));
}
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: apache/incubator-dubbo

protected static Set<String> getSubProperties(Map<String, String> properties, String prefix) {
  return properties.keySet().stream().filter(k -> k.contains(prefix)).map(k -> {
    k = k.substring(prefix.length());
    return k.substring(0, k.indexOf("."));
  }).collect(Collectors.toSet());
}
origin: spring-projects/spring-framework

@Override
public Set<String> keySet() {
  return this.headers.getHeaderNames().stream()
      .map(HttpString::toString)
      .collect(Collectors.toSet());
}
origin: spring-projects/spring-framework

/**
 * Return declared "producible" types but only among those that also
 * match the "methods" and "consumes" conditions.
 */
public Set<MediaType> getProducibleMediaTypes() {
  return this.partialMatches.stream().filter(PartialMatch::hasConsumesMatch).
      flatMap(m -> m.getInfo().getProducesCondition().getProducibleMediaTypes().stream()).
      collect(Collectors.toCollection(LinkedHashSet::new));
}
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: spring-projects/spring-framework

private Mono<Map<String, Object>> initAttributes(ServerWebExchange exchange) {
  if (this.sessionAttributePredicate == null) {
    return EMPTY_ATTRIBUTES;
  }
  return exchange.getSession().map(session ->
      session.getAttributes().entrySet().stream()
          .filter(entry -> this.sessionAttributePredicate.test(entry.getKey()))
          .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
}
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

protected static Set<String> getSubProperties(Map<String, String> properties, String prefix) {
  return properties.keySet().stream().filter(k -> k.contains(prefix)).map(k -> {
    k = k.substring(prefix.length());
    return k.substring(0, k.indexOf("."));
  }).collect(Collectors.toSet());
}
origin: spring-projects/spring-framework

/**
 * Return declared "consumable" types but only among those that also
 * match the "methods" condition.
 */
public Set<MediaType> getConsumableMediaTypes() {
  return this.partialMatches.stream().filter(PartialMatch::hasMethodsMatch).
      flatMap(m -> m.getInfo().getConsumesCondition().getConsumableMediaTypes().stream()).
      collect(Collectors.toCollection(LinkedHashSet::new));
}
origin: apache/kafka

  private Set<String> topics() {
    return updateResponse.topicMetadata().stream()
        .map(MetadataResponse.TopicMetadata::topic)
        .collect(Collectors.toSet());
  }
}
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());
}
java.util.streamStreamcollect

Javadoc

Performs a mutable reduction operation on the elements of this stream. A mutable reduction is one in which the reduced value is a mutable result container, such as an ArrayList, and elements are incorporated by updating the state of the result rather than by replacing the result. This produces a result equivalent to:
 
R result = supplier.get();

Like #reduce(Object,BinaryOperator), collect operations can be parallelized without requiring additional synchronization.

This is a terminal operation.

Popular methods of Stream

  • map
  • filter
  • forEach
  • findFirst
  • of
  • anyMatch
  • flatMap
  • sorted
  • toArray
  • findAny
  • count
  • allMatch
  • count,
  • allMatch,
  • concat,
  • reduce,
  • mapToInt,
  • distinct,
  • empty,
  • noneMatch,
  • iterator

Popular in Java

  • Finding current android device location
  • startActivity (Activity)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • BigInteger (java.math)
    An immutable arbitrary-precision signed integer.FAST CRYPTOGRAPHY This implementation is efficient f
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • StringTokenizer (java.util)
    Breaks a string into tokens; new code should probably use String#split.> // Legacy code: StringTo
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • Notification (javax.management)
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now