Java tutorial
public class Main { public static void main(String[] args) { try { String str1 = "java2s.com"; System.out.println("string1 = " + str1); // copy the contents of the String to a byte array byte[] arr = str1.getBytes("ASCII"); String str2 = new String(arr); System.out.println("new string = " + str2); } catch (Exception e) { System.out.print(e.toString()); } } }