Java examples for java.lang:char Array
Convert an array of 8 bit characters into a string.
//package com.java2s; public class Main { public static void main(String[] argv) { byte[] bytes = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 }; System.out.println(fromByteArray(bytes)); }/* w ww.j ava2s . c om*/ /** * Convert an array of 8 bit characters into a string. * * @param bytes 8 bit characters. * @return resulting String. */ public static String fromByteArray(byte[] bytes) { return new String(asCharArray(bytes)); } /** * Do a simple conversion of an array of 8 bit characters into a string. * * @param bytes 8 bit characters. * @return resulting String. */ public static char[] asCharArray(byte[] bytes) { char[] chars = new char[bytes.length]; for (int i = 0; i != chars.length; i++) { chars[i] = (char) (bytes[i] & 0xff); } return chars; } }