Friday, October 10, 2025
HomeLanguagesJavaProgram to convert IntStream to String in Java

Program to convert IntStream to String in Java

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:

  1. Get the Instream to be converted.
  2. Convert the IntStream into String with the help of StringBuilder
  3. Collect the formed StringBuilder
  4. Convert the StringBuilder into String using toString() methods.
  5. Print the formed String.

Below is the implementation of the above approach:




// Java program to convert
// String to IntStream
  
import java.util.stream.IntStream;
  
class GFG {
    public static void main(String[] args)
    {
  
        // Get the String to be converted
        IntStream intStream = "Geeks".chars();
  
        // Convert IntStream to String
        String string = intStream
                            .collect(StringBuilder::new,
                                     StringBuilder::appendCodePoint,
                                     StringBuilder::append)
                            .toString();
  
        // Print the String
        System.out.println("String: " + string);
    }
}


Output:

String: Geeks
RELATED ARTICLES

Most Popular

Dominic
32349 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6715 POSTS0 COMMENTS
Nicole Veronica
11878 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6837 POSTS0 COMMENTS
Ted Musemwa
7097 POSTS0 COMMENTS
Thapelo Manthata
6792 POSTS0 COMMENTS
Umr Jansen
6791 POSTS0 COMMENTS