Given a String, the task is to convert this String into an IntStream containing the ASCII values of the characters as the elements.
Examples:
Input: String = Geeks
Output: 71, 101, 101, 107, 115
Input: String = GeeksForGeeks
Output: 71, 101, 101, 107, 115, 70, 111, 114, 71, 101, 101, 107, 115
Algorithm:
- Get the String to be converted.
- Convert it into IntStream using chars() method.
- Print the formed IntStream.
Below is the implementation of the above approach:
import java.util.stream.IntStream;
class GFG {
public static void main(String[] args)
{
String string = "Geeks" ;
System.out.println( "String: " + string);
IntStream intStream = string.chars();
intStream.forEach(System.out::println);
}
}
|
Output:
String: Geeks
71
101
101
107
115