Mega Code Archive

 
Categories / Java Tutorial / Data Type
 

Obtaining the Characters in a String as an Array of Bytes

public class MainClass {   public static void main(String[] arg) {     String text = "To be or not to be";        // Define a string     byte[] textArray = text.getBytes();          for(byte b: textArray){       System.out.println(b);            }   } } 84 111 32 98 101 32 111 114 32 110 111 116 32 116 111 32 98 101