Program to convert IntStream to String in Java
Last Updated :
11 Dec, 2018
Given a Instream containing ASCII values, the task is to convert this Instream into a String containing the characters corresponding to the ASCII values.
Examples:
Input: IntStream = 71, 101, 101, 107, 115
Output: Geeks
Input: IntStream = 71, 101, 101, 107, 115, 70, 111, 114, 71, 101, 101, 107, 115
Output: GeeksForGeeks
Algorithm:
- Get the Instream to be converted.
- Convert the IntStream into String with the help of StringBuilder
- Collect the formed StringBuilder
- Convert the StringBuilder into String using toString() methods.
- Print the formed String.
Below is the implementation of the above approach:
import java.util.stream.IntStream;
class GFG {
public static void main(String[] args)
{
IntStream intStream = "Geeks" .chars();
String string = intStream
.collect(StringBuilder:: new ,
StringBuilder::appendCodePoint,
StringBuilder::append)
.toString();
System.out.println( "String: " + string);
}
}
|
Output:
String: Geeks
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...