Java IntStream codePoints()方法及示例

来源:这里教程网 时间:2026-02-17 20:56:16 作者:

Java IntStream codePoints()方法及示例

IntStream类的 codePoints() 方法是用来从给定的序列中获取码点值的流。它返回作为参数的字符的ASCII值。

语法

public IntStream codePoints()

返回值: 该方法返回IntStream代码值。

下面的例子说明了codePoints()方法的使用。

例1 :

// Java program to demonstrate// codePoints() method of IntStream class  import java.util.stream.IntStream;  public class GFG {    public static void main(String args[])    {          // String to be converted        String str = "GeeksForGeeks";          // Convert the string to code values        // using codePoints() method        IntStream stream = str.codePoints();          System.out.println("ASCII Values are: ");          // Print the code points        stream.forEach(System.out::println);    }}

输出。

ASCII Values are: 711011011071157011111471101101107115

例2 :

// Java program to demonstrate// codePoints() method of IntStream class  import java.util.stream.IntStream;  public class GFG {    public static void main(String args[])    {          // String to be converted        String str = "A computer science"                     + " portal for geeks";          // Convert the string to code values        // using codePoints() method        IntStream stream = str.codePoints();          System.out.println("ASCII Values are: ");          // Print the code points        stream.forEach(System.out::println);    }}

输出。

ASCII Values are: 65329911110911211711610111432115991051011109910132112111114116971083210211111432103101101107115

相关推荐