Following topics give the conversions between different concepts of Java like, date to string, array to string, string to arraylist, numbers to words etc. Arrays 1. Byte Array to Char Array – Char Array to Byte Array 2. String to a) char array and b) byte Array 3. Char array…
Char array and Byte array to String Java
Sometimes, it is necessary to convert an array of bytes and characters into a string in Java coding. Conversion of array to string is easy in Java, just use String constructors. Following Example on array to String converts char array and byte array into string form.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
public class Demo { public static void main(String args[]) { char letters[] = { 'h', 'e', 'l', 'l', 'o' }; String str1 = new String(letters); System.out.println("letters array as string: " + str1); byte alphabets[] = { 97, 98, 99, 100, 101 }; String str2 = new String(alphabets); System.out.println("alphabets array as string: " + str2); } } |
Output Screenshot on Standard…