# [Java] Getting size of byte[] array in If statement



## Lyoko

I am relatively new to Java, and have no idea how to get the size of a byte[] array and use it in a condition. I've tried size but it errors. Here is what I've got:

Code:



Code:


public void New(byte j, byte[] x) {
if(x[B].Size[/B] = 9) 
    {
byte a = x[0];
byte b = x[1];
byte c = x[2];
byte d = x[3];
byte e = x[4];
byte f = x[5];
byte g = x[6];
byte h = x[7];
byte i = x[8];
     }
}

Is there a class similar to visual basic's ubound that I may use? Thanks.


----------



## Lyoko

bump


----------



## xdaseinx

length


----------



## Lyoko

Quote:


Originally Posted by *xdaseinx* 
length

Type mismatch: cannot convert from int to boolean.
I've tried it earlier (x.length) but still nothing


----------



## xdaseinx

You are using "=" which results in initialization in your If conditional. The use of .length is correct.
use "=="

public void New(byte j, byte[] x) {
*if(x.length == 9)*
{
byte a = x[0];
byte b = x[1];
byte c = x[2];
byte d = x[3];
byte e = x[4];
byte f = x[5];
byte g = x[6];
byte h = x[7];
byte i = x[8];
}
}


----------



## Lyoko

Worked. Thanks!


----------

