initializing a boolean array in java

前端 未结 6 1083
花落未央
花落未央 2020-12-23 08:35

I have this code

public static Boolean freq[] = new Boolean[Global.iParameter[2]];
freq[Global.iParameter[2]] = false;

could someone tell m

6条回答
  •  Happy的楠姐
    2020-12-23 09:31

    Arrays in Java start indexing at 0. So in your example you are referring to an element that is outside the array by one.

    It should probably be something like freq[Global.iParameter[2]-1]=false;

    You would need to loop through the array to initialize all of it, this line only initializes the last element.

    Actually, I'm pretty sure that false is default for booleans in Java, so you might not need to initialize at all.

    Best Regards

提交回复
热议问题