use of java.util.stream.IntStream in project KursJava by SamouczekProgramisty.
the class StreamCreation method main.
public static void main(String[] args) throws FileNotFoundException {
Stream<Integer> stream1 = new LinkedList<Integer>().stream();
Stream<Integer> stream2 = Arrays.stream(new Integer[] {});
Stream<String> stream3 = Pattern.compile(".").splitAsStream("some longer sentence");
DoubleStream doubles = DoubleStream.of(1, 2, 3);
IntStream ints = IntStream.range(0, 123);
LongStream longs = LongStream.generate(() -> 1L);
DoubleStream randomDoubles = new Random().doubles();
IntStream randomInts = new Random().ints();
LongStream randomLongs = new Random().longs();
Stream.empty();
try (Stream<String> lines = new BufferedReader(new FileReader("file.txt")).lines()) {
//
}
}
use of java.util.stream.IntStream in project KursJava by SamouczekProgramisty.
the class LazyStreams method main.
public static void main(String[] args) {
IntStream numbersStream = IntStream.range(0, 8);
System.out.println("Przed");
numbersStream = numbersStream.filter(n -> n % 2 == 0);
System.out.println("W trakcie 1");
numbersStream = numbersStream.map(n -> {
System.out.println("> " + n);
return n;
});
System.out.println("W trakcie 2");
numbersStream = numbersStream.limit(2);
System.out.println("W trakcie 3");
numbersStream.forEach(System.out::println);
System.out.println("Po");
}
use of java.util.stream.IntStream in project code-sample by SprintBean.
the class StreamTest method primitiveTypeStreamTest.
@Test
public void primitiveTypeStreamTest() {
// 创建一个整数流
IntStream stream = IntStream.of(1, 1, 2, 3, 5);
int[] arr = { 1, 2, 3, 4, 5 };
stream = Arrays.stream(arr);
// 生成0到99
// Upper bound is excluded
IntStream zeroToNinetyNine = IntStream.range(0, 100);
zeroToNinetyNine.forEach((x) -> log.info(x + ""));
// Upper bound is included
IntStream zeroToHundred = IntStream.rangeClosed(0, 100);
// 统计字符串数组中的长度 存储在整数流中
String[] names = { "Tom", "Jack", "Mary", "Adams", "HuangJunlin" };
IntStream intStream = Stream.of(names).mapToInt(String::length);
intStream.forEach(x -> log.info(x + ""));
// 装箱
Stream<Integer> integers = IntStream.range(0, 100).boxed();
integers.forEach(x -> log.info(x + ""));
}
use of java.util.stream.IntStream in project tutorials by eugenp.
the class GuavaStreamsUnitTest method concatStreamsOfTypeIntStream.
@Test
public void concatStreamsOfTypeIntStream() {
IntStream combinedStreams = Streams.concat(IntStream.range(1, 20), IntStream.range(21, 40));
assertNotNull(combinedStreams);
assertStreamEquals(combinedStreams, IntStream.concat(IntStream.range(1, 20), IntStream.range(21, 40)));
}
use of java.util.stream.IntStream in project tutorials by eugenp.
the class StreamsUtility method main.
public static void main(String[] args) {
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);
// Using Collection
Stream<Integer> streamFromCollection = Streams.stream(numbers);
// Using Iterator
Stream<Integer> streamFromIterator = Streams.stream(numbers.iterator());
// Using Iterable
Stream<Integer> streamFromIterable = Streams.stream((Iterable<Integer>) numbers);
// Using Optional
Stream<Integer> streamFromOptional = Streams.stream(Optional.of(1));
// Using OptionalLong to LongStream
LongStream streamFromOptionalLong = Streams.stream(OptionalLong.of(1));
// Using OptionalInt to IntStream
IntStream streamFromOptionalInt = Streams.stream(OptionalInt.of(1));
// Using OptionalDouble to DoubleStream
DoubleStream streamFromOptionalDouble = Streams.stream(OptionalDouble.of(1.0));
Stream<Integer> concatenatedStreams = Streams.concat(streamFromCollection, streamFromIterable, streamFromIterator);
List<Integer> integers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
// This will return 10
Optional<Integer> lastItem = Streams.findLast(integers.stream());
Streams.zip(Stream.of("candy", "chocolate", "bar"), Stream.of("$1", "$2", "$3"), (arg1, arg2) -> arg1 + ":" + arg2);
}
Aggregations