Questions tagged [intstream]

10 questions
2
votes
2 answers

Java multi-threading on an Intel core i5 processor

I am working on a PC with an Intel Core i5 processor which reports to have 12 processors, which I believe is comprised of 6 cores each with two threads. I have done some research and it appears that Java uses kernel threading. I need to dramatically…
cnash
  • 23
  • 3
2
votes
1 answer

IntStream equivalence in Swift

I am investigating some of the components in Java and wondering what is the best practice to convert the following Java code snippet to Swift. public void doTest(ArrayList items) { // I know that I should check the count of items. Let's…
thus
  • 1,326
  • 1
  • 14
  • 23
2
votes
2 answers

IntStream iterate function with filter

I was reading this book called Modern Java in Action and one part of code I could not comprehend. IntStream.iterate(0, n -> n + 4) .filter(n -> n < 100) .forEach(System.out::println); Authors says that code…
Rakesh Chauhan
  • 413
  • 4
  • 7
1
vote
1 answer

Dynamically determine the IntStream.range()

I hve this code which loops through lines of integers and enters them into a List: BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); List> arr = new ArrayList<>(); IntStream.range(0, 12).forEach(i…
runnerpaul
  • 5,942
  • 8
  • 49
  • 118
1
vote
1 answer

returning LinkedHashMap from IntStream, Java 8

I have this code. private static Map> alternativeMethod(AudioFormat audioformat, List listChunkDTO, long index, int sizeChunk) { int numBytesPerSample = audioformat.getSampleSizeInBits() / 8; …
joseluisbz
  • 1,491
  • 1
  • 36
  • 58
0
votes
1 answer

How is this Eratosthenes Sieve implementation is working internally?

I found this code that seems to be the non-optimal version of the Sieve of Erastothenes, it gets the N first prime numbers into an array. private IntPredicate p = x -> true; private int[] primes(int n) { return IntStream.iterate(2, i -> i…
0
votes
1 answer

incompatible types: bad type in conditional expression void cannot be converted to Boolean. please assist

Here is my code below..... I am trying to use " (...)? IntStream.range(...).forEach(i->{......}):false; public class CheckAnagram { boolean status=false; int countForStr1=0; int countForStr2=0; String str1ToLowerCase,str2ToLowerCase; public boolean…
-1
votes
1 answer

Issue with Java IntStream whilst trying to solve a codewars problem (Prime Streaming PG-13)

I signed up on codewars in March and I have finished a number of challenges. I am encountering difficulty with the following. The name is Prime Streaming (PG-13) and is highlighted below. Create an endless stream of prime numbers - a bit like…
-2
votes
3 answers

Convert array to a Map of array index to value

What's wrong with this code? int[] nums = new int[] {8, 3, 4}; Map val2Idx = IntStream.range(0, nums.length) .collect(Collectors.toMap(idx -> idx, idx -> nums[idx])); I'm hoping to produce a Map with these…
kane
  • 5,465
  • 6
  • 44
  • 72
-3
votes
2 answers

Concat different Streams and print on Java

I'm trying to print a concat Stream that includes String and Integer elements. I've try a few ways, but none of them works. I can't find a proper way to do it on internet. It's just a testing code as you can see: import java.util.stream.*; class…
Shinington
  • 17
  • 1
  • 6