Obtaining the Characters in a String as an Array of Bytes : String vs Byte Array « Data Type « Java Tutorial






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








2.27.String vs Byte Array
2.27.1.Obtaining the Characters in a String as an Array of Bytes
2.27.2.Construct string from subset of char array.
2.27.3.Converts bytes to a hex string
2.27.4.Get byte array from hex string
2.27.5.Gets a hex string from byte array.
2.27.6.Convert bytes to a base16 string.
2.27.7.Convert a string into a byte array in hex format.
2.27.8.Convert a byte array to a String with a hexidecimal format.
2.27.9.Convert a hexidecimal string generated by toHexString() back into a byte array.
2.27.10.Converts a hex string to a byte array.
2.27.11.Get 7-bit ASCII character array from input String.