Convert Hex to String in Java

Sheeraz Gul May 04, 2022
Convert Hex to String in Java

The Hex or Hexadecimal strings are made of a hexadecimal numbering system that uses the Base of 16 system. The hex is used to represent the long binary values.

In Java, we can convert a normal string to a hex string using the method toHexString(), but to convert a hex string to a normal one, we need to convert each string character from hex to char. This tutorial demonstrates how to convert a hex string to a text string in Java.

Convert Hex to String in Java

Converting the hexadecimal to string is a step-by-step process in Java.

  1. Get the hexadecimal value of the string.
  2. Use the method toCharArray to convert the string into a character array.
  3. Read every two characters from the array and convert them to the string.
  4. Now, Parse the strings obtained above into base 16 integers and then cast them into char.
  5. Finally, add all the characters to one string by concatenating them.

Source Code:

package delftstack;

import java.util.Scanner;
public class Hex_String {
    public static void main(String args[]) {
        Scanner sc = new Scanner(;
        System.out.println("Please Enter a Hexadecimal value you want to convert: ");
        String HexString =;
        String OutputString = new String();
        char[] Temp_Char = HexString.toCharArray();
        for(int x = 0; x < Temp_Char.length; x=x+2) {
            String Temp_String = ""+Temp_Char[x]+""+Temp_Char[x+1];
            char character = (char)Integer.parseInt(Temp_String, 16);
            OutputString = OutputString + character;

        System.out.println("The String of the hexadecimal value is: ");

The code above will ask for a hexadecimal value and then convert it.


Please Enter a Hexadecimal value you want to convert:
The String of the hexadecimal value is:
Hello! This is
Author: Sheeraz Gul
Sheeraz Gul avatar Sheeraz Gul avatar

Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.

LinkedIn Facebook

Related Article - Java Hex