Java examples for java.lang:byte Array to char
Rewrite a byte array as a char array
/******************************************************************************* * Copyright (c) 2008 JCrypTool Team and Contributors * /*from www. j a va 2s. c om*/ * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse * Public License v1.0 which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html *******************************************************************************/ //package com.java2s; public class Main { public static void main(String[] argv) throws Exception { byte[] input = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 }; System.out.println(java.util.Arrays.toString(toCharArray(input))); } /** * Rewrite a byte array as a char array * * @param input - the byte array * @return char array */ public static char[] toCharArray(byte[] input) { char[] result = new char[input.length]; for (int i = 0; i < input.length; i++) { result[i] = (char) input[i]; } return result; } }