Here you can find the source of toHexString(String str)
public static String toHexString(String str)
//package com.java2s; import java.io.UnsupportedEncodingException; public class Main { public static String toHexString(String str) { byte[] byteArray; try {//from w w w .j av a2 s .c o m byteArray = str.getBytes("utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); byteArray = str.getBytes(); } return bytesToHexString(byteArray); } public static String bytesToHexString(byte[] bytes) { StringBuilder sb = new StringBuilder(""); if (bytes == null || bytes.length <= 0) { return null; } for (int i = 0; i < bytes.length; i++) { int v = bytes[i] & 0xFF; String hv = Integer.toHexString(v); if (hv.length() < 2) { sb.append(0); } sb.append(hv); } return sb.toString(); } }