Javatpoint Logo
Javatpoint Logo

Java ByteArrayOutputStream toString() method

The toString() method of Java ByteArrayOutputStream class is used to convert the buffer's contents into a string by decoding the bytes using the named charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the byte array.

Syntax:

Parameters:

charsetName - the name of a supported charset

Returns

The toString() method returns the String decoded from the buffer's contents.

Throws:

UnsupportedEncodingException - If the name charset is not supported.

Example 1

Test it Now

Output:

âäàá
ABCDE

Example 2

Test it Now

Output:

ÎÏÌβ!
VWXYZ

Java ByteArrayOutputStream toString() method

The toString() method of Java ByteArrayOutputStream class is used to convert the buffer?s contents into a string decoding bytes using the platform?s default character set.

This method transforms an object into a string. It is used to construct a string containing the information on an object that can be printed, and we can redefine it for a specific class.

Syntax:

Overrides

toString() method in class Object

Returns

The toString() method returns the string representation of the object.

Example 1

Test it Now

Output:

VWXYZ

Example 2

Test it Now

Output:

KLMNO






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA