Cheap VPS & Xen Server

Residential Proxy Network - Hourly & Monthly Packages

String getBytes()


The java string getBytes() method returns the byte array of the string. In other words, it returns sequence of bytes.

Signature

There are 3 variant of getBytes() method. The signature or syntax of string getBytes() method is given below:

  1. public byte[] getBytes()
  2. public byte[] getBytes(Charset charset)
  3. public byte[] getBytes(String charsetName)throws UnsupportedEncodingException

Returns

sequence of bytes.


Java String getBytes() method example

  1. public class StringGetBytesExample{
  2. public static void main(String args[]){
  3. String s1=“ABCDEFG”;
  4. byte[] barr=s1.getBytes();
  5. for(int i=0;i<barr.length;i++){
  6. System.out.println(barr[i]);
  7. }
  8. }}

Output:

65
66
67
68
69
70
71

Comments

comments