• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
November 09, 2022 |1.3K Views
Java Program to Convert Byte Array to String
  Share   Like
Description
Discussion

In this video, we will see how to convert an Byte array to string.

As we know that computer stores information in 0 and 1 to represent alphabets we have a system of ASCII code to first convert symbols and alphabets to number and then to 0 and 1. Similarly there is a system by using that we can store strings that is in the Bytes format. 

There are two ways to do so, and both have a time and space complexity of O(1) and O(N) here N is the length of the string. Here space complexity is O(N) because we will be using an array of length N to store all of these bytes. 

We can use String class Constructor to convert byte array to string by passing the bytes array in the constructor while initialising a new string. Although the second method is very similar to the first one, the only difference is that of the encoding format. Earlier we were using bytes array and in the second method we use UTF-8 encoded characters/string.

Java program to convert byte array to string:
https://www.geeksforgeeks.org/java-program-to-convert-byte-array-to-string/

Read More