Java Online Compiler
Example: Get String Length using Stream API (codePoints) in Java
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// Get String Length using Stream API (codePoints) import java.util.Scanner; // Included for consistent structure, though not strictly used here // Main class containing the entry point of the program public class Main { public static void main(String[] args) { // Step 1: Initialize a string String str = "Hello World"; // Step 2: Get an IntStream of code points from the string and count them long length = str.codePoints().count(); // count() returns a long System.out.println("String: \"" + str + "\""); System.out.println("Length (using Stream API codePoints().count()): " + length); } }
Output
Clear
ADVERTISEMENTS