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
🌐
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.
🌐
DigitalOcean
digitalocean.com › community › tutorials › string-byte-array-java
String to byte array, byte array to String in Java | DigitalOcean
From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.
🌐
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 - For binary data byte[], try Base64 encoding. The below example convert a string to a byte array or byte[] and vice versa.
🌐
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 - In Java, we can use str.getBytes(StandardCharsets.UTF_8) to convert a String into a byte[]. String str = "This is a String"; // default charset, a bit dangerous byte[] output1 = str.getBytes();
🌐
Study.com
study.com › business courses › java programming tutorial & training
Java: Convert String to Byte Array - Video | Study.com
January 6, 2018 - The process begins by importing Java's Arrays utility which provides necessary tools for this conversion. When converting a string to a byte array, the getBytes() method breaks down each character into its ASCII value.
🌐
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 - To convert a string to a byte array, we use the getBytes(Charset) method In Java that transforms the string into a sequence of bytes based on a specified character encoding.
🌐
Study.com
study.com › business courses › java programming tutorial & training
Java: Convert String to Byte Array - Lesson | Study.com
January 6, 2018 - Therefore, the fifth letter in our string will be number 4 to Java. Each step is relatively straightforward. First we set the fourth index, the fifth item, to 126. Next, we simply declare a new string and give it the value of the byte array.
Find elsewhere
🌐
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
1 month ago - A String may contain a numeric value as text, while byte is a primitive data type used to store small integer values. Java provides methods in the Byte wrapper class to convert a numeric String into a byte.
🌐
LabEx
labex.io › tutorials › java-convert-string-to-byte-117428
Convert String to Byte in Java | LabEx
Convert the string to bytes using the getBytes() method of the String class.
🌐
How to do in Java
howtodoinjava.com › home › java array › convert byte array to string in java and string to byte[]
Convert Byte Array to String in Java and String to byte[]
June 5, 2017 - We still pass StandardCharsets.UTF_8 explicitly, because the code reads the same on every JDK and every machine, and nobody has to check the startup flags. The constructor String(byte[], Charset) decodes the bytes with the given charset.
🌐
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, ...
🌐
Codemia
codemia.io › home › knowledge hub › how to convert java string into byte[]?
How to convert Java String into byte[]? | Codemia
January 25, 2025 - To convert a String to a byte[] in Java, you use the getBytes method of the String class. This method converts the characters into bytes using the specified charset.
🌐
Dot Net Perls
dotnetperls.com › convert-string-byte-array-java
Java - Convert String to Byte Array - Dot Net Perls
May 26, 2023 - With the String constructor, we create a String based on the elements in a byte array. And with String's getBytes methods, we convert String data to byte arrays.
🌐
Oracle
docs.oracle.com › javase › tutorial › i18n › text › string.html
Byte Encodings and Strings (The Java™ Tutorials > Internationalization > Working with Text)
The StringConverter program prints out the values in the utf8Bytes and defaultBytes arrays to demonstrate an important point: The length of the converted text might not be the same as the length of the source text. Some Unicode characters translate into single bytes, others into pairs or triplets of bytes. The printBytes method displays the byte arrays by invoking the byteToHex method, which is defined in the source file, UnicodeFormatter.java.
🌐
TutorialsPoint
tutorialspoint.com › java-program-to-convert-string-to-byte
Java Program to convert string to byte
August 1, 2024 - Given String is: 65 Type before converting: String String after converting to Byte: 65 Type after converting: Byte · The parseByte() method of Java Byte class parses the specified string argument as a signed decimal byte.
🌐
Xojo Programming Forum
forum.xojo.com › general
How To Convert A String To Byte()? - General - Xojo Programming Forum
October 14, 2013 - In Java, the String class has a getBytes() method, which simply returns an array of bytes using the default platform encoding. Perhaps I’m blind, but I can’t seem to find any equivalent built-in way to do this in Xojo. …
🌐
LabEx
labex.io › tutorials › java-conversion-between-string-and-byte-array-117395
String to Byte Array Conversion | Java Programming | LabEx
import java.nio.ByteBuffer; Charset charset = StandardCharsets.UTF_16; byte[] byteArr = {-2, -1, 0, 100, 0, 101, 0, 109, 0, 111, 0, 33, -10}; String stringFromBytes = charset.decode(ByteBuffer.wrap(byteArr)).toString();