Convert byte array to char in Java
Description
The following code shows how to convert byte array to char.
Example
//from ww w . ja v a 2s .c o m
import java.nio.ByteBuffer;
public class Main {
public static char convertToCharacter(byte[] array) {
ByteBuffer buffer = ByteBuffer.wrap(array);
return buffer.getChar();
}
public static void main(String[] argv) {
System.out.println(convertToCharacter(new byte[]{67}));
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »