কম্পিউটার টিউটোরিয়াল

জাভা ৯-এ String ক্লাসে যোগ করা নতুন মেথডগুলো কী কী?

একটি String জাভাতে ইমিউটেবল ক্লাস এবং জাভা ৯-এ String ক্লাসে দুটি নতুন মেথড যোগ করা হয়েছে। সেগুলো হলো chars() এবং codePoints()। এই দুটি মেথডই IntStream অবজেক্ট রিটার্ন করে।

১) chars():

String ক্লাসের chars() মেথড এই সিকোয়েন্স থেকে চার ভ্যালুগুলো জিরো-এক্সটেন্ড করে int-এর একটি স্ট্রিম রিটার্ন করে।

সিনট্যাক্স

public IntStream chars()

উদাহরণ

import java.util.stream.IntStream;

public class StringCharsMethodTest {
    public static void main(String args[]) {
        String str = "Welcome to TutorialsPoint";
        IntStream intStream = str.chars();
        intStream.forEach(x -> System.out.printf("-%s", (char)x));
    }
}

আউটপুট

-W-e-l-c-o-m-e- -t-o- -T-u-t-o-r-i-a-l-s-P-o-i-n-t

২) codePoints():

codePoints() মেথড এই সিকোয়েন্স থেকে কোড পয়েন্ট ভ্যালুগুলোর একটি স্ট্রিম রিটার্ন করে।

সিনট্যাক্স

public IntStream codePoints()

উদাহরণ

import java.util.stream.IntStream;

public class StringCodePointsMethodTest {
    public static void main(String args[]) {
        String str = "Welcome to Tutorix";
        IntStream intStream = str.codePoints();
        intStream.forEach(x -> System.out.print(new StringBuilder().appendCodePoint(x)));
    }
}

আউটপুট

Welcome to Tutorix
  1. জাভা ৯-এ JShell-এ পালন করণীয় নিয়মগুলো

  2. জাভা ৯-এ @Deprecated অ্যানোটেশনের উন্নতি

  3. জাভাতে Cursor ক্লাসের গুরুত্ব

  4. জাভাতে ক্লাসের বিভিন্ন প্রকার কী কী?