Java ByteArrayOutputStream toString() methodThe 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 ReturnsThe toString() method returns the String decoded from the buffer's contents. Throws:UnsupportedEncodingException - If the name charset is not supported. Example 1Test it NowOutput: âäàá ABCDE Example 2Test it NowOutput: ÎÏÌβ! VWXYZ Java ByteArrayOutputStream toString() methodThe 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:OverridestoString() method in class Object ReturnsThe toString() method returns the string representation of the object. Example 1Test it NowOutput: VWXYZ Example 2Test it NowOutput: KLMNO
Next TopicJava ByteArrayOutputStream Class
|