The object your method decompressGZIP() needs is a byte[].

So the basic, technical answer to the question you have asked is:

byte[] b = string.getBytes();
byte[] b = string.getBytes(Charset.forName("UTF-8"));
byte[] b = string.getBytes(StandardCharsets.UTF_8); // Java 7+ only

However the problem you appear to be wrestling with is that this doesn't display very well. Calling toString() will just give you the default Object.toString() which is the class name + memory address. In your result [B@38ee9f13, the [B means byte[] and 38ee9f13 is the memory address, separated by an @.

For display purposes you can use:

Arrays.toString(bytes);

But this will just display as a sequence of comma-separated integers, which may or may not be what you want.

To get a readable String back from a byte[], use:

String string = new String(byte[] bytes, Charset charset);

The reason the Charset version is favoured, is that all String objects in Java are stored internally as UTF-16. When converting to a byte[] you will get a different breakdown of bytes for the given glyphs of that String, depending upon the chosen charset.

Answer from Stewart on Stack Overflow
🌐
W3Schools
w3schools.com › java › ref_string_getbytes.asp
Java String getBytes() Method
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A ... The getBytes() method converts a string into an array of bytes.
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-convert-a-string-value-to-byte-value-in-java-with-examples
How to Convert a String value to Byte value in Java with Examples - GeeksforGeeks
July 12, 2025 - // Java Program to convert string to byte class GFG { // Function to convert String to Byte public static byte convertStringToByte(String str) { // Convert string to byte // using parseByte() method return Byte.parseByte(str); } // Driver code ...
🌐
Mkyong
mkyong.com › home › java › how to convert string to byte[] in java?
How to convert String to byte[] in Java? - Mkyong.com
January 17, 2022 - String str = "This is a String"; // default charset, a bit dangerous byte[] output1 = str.getBytes(); // in old days, before java 1.7 byte[] output2 = str.getBytes(Charset.forName("UTF-8")); // the best , java 1.7+ , new class StandardCharsets ...
🌐
LabEx
labex.io › tutorials › java-convert-string-to-byte-117428
Convert String to Byte in Java | LabEx
In this lab, we learned how to convert a string to byte in Java using the getBytes() method and how to specify a charset.
🌐
DigitalOcean
digitalocean.com › community › tutorials › string-byte-array-java
String to byte array, byte array to String in Java | DigitalOcean
August 3, 2022 - We can use String class getBytes() method to encode the string into a sequence of bytes using the platform’s default charset. This method is overloaded and we can also pass Charset as argument. Here is a simple program showing how to convert String to byte array in java.
🌐
Java67
java67.com › 2017 › 10 › 3-ways-to-convert-string-to-byte-array-in-java.html
3 ways to convert String to byte array in Java - Example Tutorial | Java67
Remember, String is made of the char array, so it involves a character to byte conversion, which is subject to character encoding intricacies. Thankfully, Java provides a convenient getBytes() method to convert String to byte array in Java, ...
🌐
Baeldung
baeldung.com › home › java › java string › convert string to byte array and reverse in java
Convert String to Byte Array and Reverse in Java | Baeldung
March 17, 2024 - A String is stored as an array of Unicode characters in Java. To convert it to a byte array, we translate the sequence of characters into a sequence of bytes. For this translation, we use an instance of Charset.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › convert-string-to-byte-array-in-java-using-getbytescharset-method
Convert String to Byte Array in Java Using getBytes(Charset) Method - GeeksforGeeks
July 23, 2025 - ... // Java program to convert a String to a byte array // using getBytes(Charset) method with UTF-8 encoding import java.nio.charset.StandardCharsets; public class StringToByteArray { public static void main(String[] args) { // sample string ...
🌐
Netjstech
netjstech.com › 2016 › 09 › converting-string-to-bytearray-java.html
Convert String to Byte Array Java Program | Tech Tutorials
Using str.getBytes("UTF-8") method to convert String to byte array will require to enclose it in a · try-catch block as UnsupportedEncodingException is thrown. To avoid that you can use str.getBytes(Charset.forName("UTF-8")) method. Java 7 onward you can also use str.getBytes(StandardChar...
🌐
Study.com
study.com › business courses › java programming tutorial & training
Java: Convert String to Byte Array - Lesson | Study.com
January 6, 2018 - Learn how to convert a string to a byte array in Java in this informative video lesson. Master the process and explore practical examples, followed by a quiz.
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › String › getBytes
Java String getBytes() - Retrieve Byte Array | Vultr Docs
December 20, 2024 - Additionally, you'll understand the implications of choosing specific character sets for encoding. Start with a simple string. Use the getBytes() method to convert it to a byte ...
🌐
Dot Net Perls
dotnetperls.com › convert-string-byte-array-java
Java - Convert String to Byte Array - Dot Net Perls
May 26, 2023 - Info With no argument, we use the system's default charset to convert the String to a byte array. Here A Charset is used based on the name provided. We test this with US-ASCII which supports 7-bit chars. Note The example uses Array.toString to "pretty-print" the arrays to the Console output. import java.io.UnsupportedEncodingException; import java.util.Arrays; public class Program { public static void main(String[] args) throws UnsupportedEncodingException { // The string we want to convert.
🌐
Oracle
docs.oracle.com › javase › tutorial › i18n › text › string.html
Byte Encodings and Strings (The Java™ Tutorials > Internationalization > Working with Text)
Conversely, you can convert a String object into a byte array of non-Unicode characters with the String.getBytes method. When invoking either of these methods, you specify the encoding identifier as one of the parameters. The example that follows converts characters between UTF-8 and Unicode.
🌐
Centron
centron.de › startseite › string to byte array and byte array to string conversion in java
String to Byte Array and Byte Array to String Conversion in Java
February 5, 2025 - We can use String class getBytes() method to encode the string into a sequence of bytes using the platform’s default charset. This method is overloaded and we can also pass Charset as argument.
🌐
Mkyong
mkyong.com › home › java › how to convert byte[] array to string in java
How to convert byte[] array to String in Java - Mkyong.com
January 18, 2022 - The below example convert a string to a byte array or byte[] and vice versa.
🌐
GeeksforGeeks
geeksforgeeks.org › java › string-getbyte-method-in-java
Java String getBytes() Method - GeeksforGeeks
November 29, 2024 - The below example shows how the getBytes() method converts a string into bytes using the platform's default character set. ... // Java program to demonstrate the getBytes() // with default charset public class GetBytes { public static void ...
🌐
Coderanch
coderanch.com › t › 585936 › java › Convert-String-Byte-Stream
Convert a String to a Byte Stream (I/O and Streams forum at Coderanch)
Seems to me like it would be more appropriate to use a FileInputStream to read a desired number of bytes from the file, process those bytes accordingly and continu that process of reading/processing until the end of the file is reached or all relevant bytes have been processed. Anyway, if that is somehow not an option you could use String#getBytes() to fill a ByteArrayInputStream, I guess.
🌐
Online String Tools
onlinestringtools.com › convert-string-to-bytes
Convert a String to Bytes – Online String Tools
This browser-based program converts a string to a byte array. The string is split into individual characters and then for each character, the program finds its byte representation, and prints it in the output area in the hexadecimal base.