Search in sources :

Example 26 with IntStream

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()) {
    // 
    }
}
Also used : Random(java.util.Random) BufferedReader(java.io.BufferedReader) DoubleStream(java.util.stream.DoubleStream) FileReader(java.io.FileReader) LongStream(java.util.stream.LongStream) IntStream(java.util.stream.IntStream)

Example 27 with IntStream

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");
}
Also used : IntStream(java.util.stream.IntStream) IntStream(java.util.stream.IntStream)

Example 28 with IntStream

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 + ""));
}
Also used : BigInteger(java.math.BigInteger) IntStream(java.util.stream.IntStream) Test(org.junit.Test)

Example 29 with IntStream

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)));
}
Also used : IntStream(java.util.stream.IntStream) Test(org.junit.Test)

Example 30 with IntStream

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);
}
Also used : DoubleStream(java.util.stream.DoubleStream) LongStream(java.util.stream.LongStream) IntStream(java.util.stream.IntStream)

Aggregations

IntStream (java.util.stream.IntStream)80 Test (org.junit.Test)20 List (java.util.List)15 ArrayList (java.util.ArrayList)13 Arrays (java.util.Arrays)10 Stream (java.util.stream.Stream)9 Random (java.util.Random)7 Collectors (java.util.stream.Collectors)7 Map (java.util.Map)5 Pattern (java.util.regex.Pattern)5 DoubleStream (java.util.stream.DoubleStream)5 LongStream (java.util.stream.LongStream)5 DecimalBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition)5 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)5 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)5 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)5 LayoutRow (org.uberfire.ext.layout.editor.api.editor.LayoutRow)5 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)5 Assert (org.junit.Assert)4 Test (org.junit.jupiter.api.Test)4