Tutorialspoint

Java IntStream anyMatch() method

import java.util.stream.IntStream;
public class Demo {
   public static void main(String[] args) {
      IntStream intStream = IntStream.of(20, 40, 60, 80, 100);
      boolean res = intStream.anyMatch(a -> a < 50);
      System.out.println(res);
   }
}

Java toArray() method of AbstractSequentialList

import java.util.LinkedList;
import java.util.AbstractSequentialList;
public class Demo {
   public static void main(String[] args) {
      AbstractSequentialList<Integer> absSequential = new LinkedList<>();
      absSequential.add(210);
      absSequential.add(290);
      absSequential.add(350);
      absSequential.add(490);
      absSequential.add(540);
      absSequential.add(670);
      absSequential.add(870);
      System.out.println("Elements in the AbstractSequentialList = "+absSequential);
      Object[] myArr = absSequential.toArray();
      System.out.println("Array = ");
      for (int i = 0; i < myArr.length; i++)
      System.out.println(myArr[i]); ;
   }
}

Java IntStream forEach() method

import java.util.*;
import java.util.stream.IntStream;
public class Demo {
   public static void main(String[] args) {
      IntStream intStream = IntStream.of(15, 30, 40, 60, 75, 90);
      intStream.forEach(System.out::println);
   }  
}

Collectors averagingInt() method in Java

import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Demo {
   public static void main(String[] args) {
      Stream<String> stream = Stream.of("20", "50", "75", "100", "150", "200");
      double res = stream.collect(Collectors.averagingInt(a -> Integer.parseInt(a)));
      System.out.println("Arithmetic Mean of the stream elements = "+res);
   }
}

Java IntStream noneMatch() method

import java.util.*;
import java.util.stream.IntStream;
public class Demo {
   public static void main(String[] args) {
      IntStream intStream = IntStream.of(15, 25, 50, 60, 80, 100, 130, 150);
      boolean res = intStream.noneMatch(a -> a < 10);
      System.out.println(res);
   }
}

Java IntStream of() method

import java.util.*;
import java.util.stream.IntStream;
public class Demo {
   public static void main(String[] args) {
      IntStream intStream = IntStream.of(10, 20, 30, 40, 50);
      intStream.forEach(System.out::println);
   }
}

Collectors counting() method in Java

import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Demo {
   public static void main(String[] args) {
      Stream<String> stream = Stream.of("25", "50", "75", "100", "125", "150", "200");
      long res = stream.collect(Collectors.counting());
      System.out.println("Count of elements in the stream = "+res);
   }
}

Java DoubleStream forEachOrdered() method

import java.util.stream.DoubleStream;
public class Demo {
   public static void main(String[] args) {
      DoubleStream doubleStream = DoubleStream.of(45.7, 67.8, 89.7, 95.6);
      doubleStream.forEachOrdered(System.out::println);
   }
}

DoubleStream allMatch() method in Java

import java.util.*;
import java.util.stream.DoubleStream;

public class Demo {
   public static void main(String[] args) {
      DoubleStream doubleStream = DoubleStream.of(15.8, 28.7, 35.7, 48.1, 78.9);
      boolean res = doubleStream.allMatch(num -> num > 10);
      System.out.println("Do all the elements match the predicate? "+res);
   }
}

DoubleStream skip() method in Java

import java.util.stream.DoubleStream;

public class Demo {
   public static void main(String[] args) {
      DoubleStream doubleStream = DoubleStream.of(39.8, 78.7, 64.7, 35.7, 47.8, 89.7, 28.7);
      System.out.println("Remaining Elements...");
      doubleStream.skip(5).forEach(System.out::println);
   }
}

Previous 1 ... 4 5 6 7 8 9 10 ... 2134 Next
Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.