How to Convert String to Hex in Java

Converting String to Hex in Java

In this example, we will show you the simple program about, how to convert a string to hex in Java. The example program has been tested and shared in the same post.

Example Program (

package com.dineshkrish;

import org.apache.commons.codec.binary.Hex;

 * @author Dinesh Krishnan

public class Converter {

	public static String convert(String str) {

		char[] ch = Hex.encodeHex(str.getBytes());

		return new String(ch);

	public static void main(String[] args) {

		String input = "Dinesh Krishnan";

		String output = convert(input);

		System.out.println("Converted ---> " + output);


Maven Dependencies (pom.xml)

<project xmlns="" xmlns:xsi=""




Converted ---> 44696e657368204b726973686e616e