Java examples for java.lang:char Array
convert To String to Byte array vis its char array
//package com.java2s; public class Main { public static void main(String[] argv) { String source = "java2s.com"; System.out.println(java.util.Arrays .toString(convertToBytes(source))); }// w w w. j a v a 2 s. c om public static byte[] convertToBytes(String source) { char[] chars = source.toCharArray(); byte[] result = new byte[chars.length]; for (int i = 0; i < chars.length; i++) { result[i] = (byte) chars[i]; } return result; } }