intstream

IntStream iterate function with filter

家住魔仙堡 提交于 2020-06-12 08:40:33
问题 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 will not terminate. The reason is that there’s no way to know in the filter that the numbers continue to increase, so it keeps on filtering them infinitely! I did not get the reason. Could someone explain it why. 回答1: You can find the answer in javadocs of IntStream#iterate : Returns an

returning LinkedHashMap from IntStream, Java 8

◇◆丶佛笑我妖孽 提交于 2020-05-21 01:57:06
问题 I have this code. private static Map<Long, List<TimePitchValue>> alternativeMethod(AudioFormat audioformat, List<ChunkDTO> listChunkDTO, long index, int sizeChunk) { int numBytesPerSample = audioformat.getSampleSizeInBits() / 8; int quantitySamples = sizeChunk / numBytesPerSample; long baseTime = quantitySamples * index; Map<Long, List<TimePitchValue>> mapListTimePitchValue = new LinkedHashMap<>(); for (int i = 0; i < quantitySamples; i++) { int time = i; List<TimePitchValue>

returning LinkedHashMap from IntStream, Java 8

南笙酒味 提交于 2020-05-21 01:56:13
问题 I have this code. private static Map<Long, List<TimePitchValue>> alternativeMethod(AudioFormat audioformat, List<ChunkDTO> listChunkDTO, long index, int sizeChunk) { int numBytesPerSample = audioformat.getSampleSizeInBits() / 8; int quantitySamples = sizeChunk / numBytesPerSample; long baseTime = quantitySamples * index; Map<Long, List<TimePitchValue>> mapListTimePitchValue = new LinkedHashMap<>(); for (int i = 0; i < quantitySamples; i++) { int time = i; List<TimePitchValue>