Contact: aviboots(AT)netvision.net.il
40,875 questions
53,283 answers
573 users
import java.util.Arrays; public class MyClass { public static void main(String args[]) { String s = "abcd"; byte[] arr = s.getBytes(); System.out.println(Arrays.toString(arr)); } } /* run: [97, 98, 99, 100] */
import java.nio.charset.StandardCharsets; public class MyClass { public static void main(String args[]) { String str = "Java"; byte[] bytes = str.getBytes(StandardCharsets.US_ASCII); for (byte ch : bytes) { System.out.print(Integer.toHexString(ch) + " "); } } } /* run: 4a 61 76 61 */