當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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: 
71
101
101
107
115
70
111
114
71
101
101
107
115

示例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: 
65
32
99
111
109
112
117
116
101
114
32
115
99
105
101
110
99
101
32
112
111
114
116
97
108
32
102
111
114
32
103
101
101
107
115


相關用法


注:本文由純淨天空篩選整理自bilal-hungund大神的英文原創作品 IntStream codePoints() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。