javabyte

Byte array - locating a character position


I have a byte array in java. That array contains '%' symbol somewhere in it. I want to find the position of that symbol in that array. Is there any way to find this?

Thanks in Advance!

[EDIT] I tried below code and it worked fine.

    byte[] b = {55,37,66};
    String s = new String(b);
    System.out.println(s.indexOf("%"));

I have a doubt. Is every character takes exactly one byte in java?


Solution

  • A correct and more direct Guava solution:

    Bytes.indexOf(byteArray, (byte) '%');