Q:

Unable to convert String to byte

I have following method in my project. 
public byte[] getbytes(){
    byte[] b;
    b = str.getBytes();
    return new byte[]{
            (byte) 0,
            (byte) 1,
            (byte) 2,
            (byte) 5,
            (byte) b 
    };
}

The last byte contains string value. So I tried to get the bytes. But I am getting following error.
error: incompatible types: byte[] cannot be converted to byte.
Even though I am using byte[] instead of Byte[]. 
According to my understanding :
The Byte class wraps a value of primitive type byte in an object. An object of type Byte contains a single field whose type is byte.
Getting confused here. What am I doing wrong here?

A:

As the others already said, byte[] is an array containing multiple bytes. There are 2 possibilies to return a byte array with the content of the String and some metadata:

You already know the String to have a length of 1:

if (str.length == 1)

but if the String wouldn´t get longer than 1, you would use a char instead:
public byte[] getbytes(){
byte b;
b = (Byte) c; //c is a char
return new byte[]{
        (byte) 0,
        (byte) 1,
        (byte) 2,
        (byte) 5,
        (byte) b 
};

}

You dont know the length of the String:
    byte[] b;
    b = str.getBytes();
    byte[] output = new byte[b.length + 4];
    output[0] = 0;
    output[1] = 1;
    output[2] = 2;
    output[3] = 5;
    for (int i = 0; i < b.length; i++) {
    output[i + 4] = b[i];
    }
    return output;
}````

