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

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

Best Java code snippets using java.util.stream.Stream.mapToInt (Showing top 20 results out of 7,857)

Refine searchRefine arrow

  • IntStream.sum
  • List.stream
  • Collection.stream
  • IntStream.toArray
origin: prestodb/presto

public InputChannels(List<Integer> inputChannels)
{
  this.inputChannels = inputChannels.stream().mapToInt(Integer::intValue).toArray();
}
origin: spring-projects/spring-framework

@Override
public DefaultDataBuffer write(ByteBuffer... buffers) {
  if (!ObjectUtils.isEmpty(buffers)) {
    int capacity = Arrays.stream(buffers).mapToInt(ByteBuffer::remaining).sum();
    ensureCapacity(capacity);
    Arrays.stream(buffers).forEach(this::write);
  }
  return this;
}
origin: neo4j/neo4j

private int[] getOrCreatePropertyKeyIds( String[] properties )
{
  return Arrays.stream( properties )
      .mapToInt( BatchInserterImpl.this::getOrCreatePropertyKeyId )
      .toArray();
}
origin: spring-projects/spring-framework

/**
 * {@inheritDoc}
 * <p>This implementation creates a single {@link DefaultDataBuffer}
 * to contain the data in {@code dataBuffers}.
 */
@Override
public DefaultDataBuffer join(List<? extends DataBuffer> dataBuffers) {
  Assert.notEmpty(dataBuffers, "DataBuffer List must not be empty");
  int capacity = dataBuffers.stream().mapToInt(DataBuffer::readableByteCount).sum();
  DefaultDataBuffer result = allocateBuffer(capacity);
  dataBuffers.forEach(result::write);
  dataBuffers.forEach(DataBufferUtils::release);
  return result;
}
origin: apache/flink

private int computeTotalMainWidth() {
  final List<AttributedString> mainLines = getMainLines();
  final List<AttributedString> mainHeaderLines = getMainHeaderLines();
  final int max1 = mainLines.stream().mapToInt(AttributedString::length).max().orElse(0);
  final int max2 = mainHeaderLines.stream().mapToInt(AttributedString::length).max().orElse(0);
  return Math.max(max1, max2);
}
origin: apache/incubator-druid

public Collection<ServerHolder> getAllServers()
{
 final int historicalSize = historicals.values().stream().mapToInt(Collection::size).sum();
 final int realtimeSize = realtimes.size();
 final List<ServerHolder> allServers = new ArrayList<>(historicalSize + realtimeSize);
 historicals.values().forEach(allServers::addAll);
 allServers.addAll(realtimes);
 return allServers;
}
origin: Vedenin/useful-java-links

private static void testFlatMapToInt() {
  System.out.println();
  System.out.println("Test flat map start");
  Collection<String> collection = Arrays.asList("1,2,0", "4,5");
  // Get sum all digit from strings
  int sum = collection.stream().flatMapToInt((p) -> Arrays.asList(p.split(",")).stream().mapToInt(Integer::parseInt)).sum();
  System.out.println("sum = " + sum); // print  sum = 12
}
origin: stackoverflow.com

 List<Integer> list = Arrays.asList(1, 2, 3, 4);
int[] arr = list.stream().mapToInt(i -> i).toArray(); //[1, 2, 3, 4]

list.set(1, null); //[1, null, 3, 4]
arr = list.stream().filter(i -> i != null).mapToInt(i -> i).toArray(); //[1, 3, 4]
origin: Vedenin/useful-java-links

private static void testMapToInt() {
  System.out.println();
  System.out.println("Test mapToInt start");
  Collection<String> collection = Arrays.asList("a1", "a2", "a3", "a1");
  // Delete first char of element and returns number
  int[] number = collection.stream().mapToInt((s) -> Integer.parseInt(s.substring(1))).toArray();
  System.out.println("number = " + Arrays.toString(number)); // print  number = [1, 2, 3, 1]
}
origin: shekhargulati/99-problems

public static <T> long lengthStream1(List<T> list) {
  return list.stream().mapToInt(x -> 1).sum();
}
origin: prestodb/presto

public InterpretedHashGenerator(List<Type> hashChannelTypes, List<Integer> hashChannels)
{
  this(hashChannelTypes, requireNonNull(hashChannels).stream().mapToInt(i -> i).toArray());
}
origin: ben-manes/caffeine

public IntStream getTopK(int k) {
 return stream.topK(k).stream().mapToInt(counter -> (int) counter.getCount());
}
origin: apache/pulsar

@Override
public int getAvailablePermits() {
  return consumers.values().stream().mapToInt(ConsumerImpl::getAvailablePermits).sum();
}
origin: stackoverflow.com

List<Integer> primes = Arrays.asList(2, 3, 5, 7, 11, 13, 17, 19, 23, 29);
IntSummaryStatistics stats = primes.stream()
                  .mapToInt((x) -> x)
                  .summaryStatistics();
System.out.println(stats);
origin: EngineHub/WorldEdit

@Nullable
public int[] getLegacyFromItem(ItemType itemType) {
  if (!itemToStringMap.containsKey(itemType)) {
    return null;
  } else {
    String value = itemToStringMap.get(itemType).stream().findFirst().get();
    return Arrays.stream(value.split(":")).mapToInt(Integer::parseInt).toArray();
  }
}
origin: apache/incubator-druid

static long requiredBufferCapacity(
  int cardinality,
  AggregatorFactory[] aggregatorFactories
)
{
 final int cardinalityWithMissingValue = cardinality + 1;
 final int recordSize = Arrays.stream(aggregatorFactories)
                .mapToInt(AggregatorFactory::getMaxIntermediateSizeWithNulls)
                .sum();
 return getUsedFlagBufferCapacity(cardinalityWithMissingValue) +  // total used flags size
   (long) cardinalityWithMissingValue * recordSize;                 // total values size
}
origin: biezhi/30-seconds-of-java8

/**
 * Input a line of numbers separated by space as integers
 * and return ArrayList of Integers.
 * eg. the String "1 2 3 4 5 6 7 8 9" is returned as an ArrayList of Integers.
 *
 * @param numbers range of numbers separated by space as a string
 * @return ArrayList of Integers
 */
public static int[] stringToIntegers(String numbers) {
  return Arrays.stream(numbers.split(" ")).mapToInt(Integer::parseInt).toArray();
}
origin: apache/incubator-druid

@Override
public int getQueryCount()
{
 return rels.stream().mapToInt(rel -> ((DruidRel) rel).getQueryCount()).sum();
}
origin: prestodb/presto

private static Function<Page, Page> enforceLayoutProcessor(List<Symbol> expectedLayout, Map<Symbol, Integer> inputLayout)
{
  int[] channels = expectedLayout.stream()
      .peek(symbol -> checkArgument(inputLayout.containsKey(symbol), "channel not found for symbol: %s", symbol))
      .mapToInt(inputLayout::get)
      .toArray();
  if (Arrays.equals(channels, range(0, inputLayout.size()).toArray())) {
    // this is an identity mapping
    return Function.identity();
  }
  return new PageChannelSelector(channels);
}
origin: prestodb/presto

private static VarcharType varcharType(List<String> values)
{
  if (values.stream().anyMatch(Objects::isNull)) {
    return VARCHAR;
  }
  return createVarcharType(values.stream().mapToInt(String::length).max().getAsInt());
}
java.util.streamStreammapToInt

Javadoc

Returns an IntStream consisting of the results of applying the given function to the elements of this stream.

This is an intermediate operation.

Popular methods of Stream

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

Popular in Java

  • Reading from database using SQL prepared statement
  • addToBackStack (FragmentTransaction)
  • setRequestProperty (URLConnection)
  • startActivity (Activity)
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • BoxLayout (javax.swing)
  • Top 12 Jupyter Notebook extensions
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