কম্পিউটার

উদাহরণ সহ জাভা স্ট্রীম গণনা() পদ্ধতি


জাভা স্ট্রীম কাউন্টিং() পদ্ধতি ব্যবহার করে স্ট্রীমের উপাদানের সংখ্যা গণনা করুন। নিচে জাভা স্ট্রিম গণনা() পদ্ধতি -

বাস্তবায়নের একটি উদাহরণ দেওয়া হল

উদাহরণ

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Demo {
   public static void main(String[] args) {
      Stream<String> stream = Stream.of("Kevin", "Jofra","Tom", "Chris", "Liam");
      // count
      long count = stream.collect(Collectors.counting());
      System.out.println("Number of elements in the stream = "+count);
   }
}

আউটপুট

Number of elements in the stream = 5

আসুন আমরা আরেকটি উদাহরণ দেখি যেখানে আমাদের পূর্ণসংখ্যা উপাদানগুলির প্রবাহ রয়েছে -

উদাহরণ

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Demo {
   public static void main(String[] args) {
      Stream<Integer> stream = Stream.of(5, 10, 20, 40, 80, 160);
      // count
      long count = stream.collect(Collectors.counting());
      System.out.println("Number of elements in the stream = "+count);
   }
}

আউটপুট

Number of elements in the stream = 6

  1. উদাহরণ সহ Java toDegrees() পদ্ধতি

  2. উদাহরণ সহ জাভা স্ট্রীম গণনা() পদ্ধতি

  3. জাভা স্ট্রীম findAny() উদাহরণ সহ

  4. কোড উদাহরণ সহ জাভা 8 স্ট্রিম টিউটোরিয়াল