Possible Lossy conversion from long to int

后端 未结 6 619
借酒劲吻你
借酒劲吻你 2021-01-01 02:15

I wish to enter one int and another long ex: 1 and 1000000000, and now I wish to create an array of size 1000000000. And then at each index of arra

6条回答
  •  借酒劲吻你
    2021-01-01 02:49

    The size of an array can only be an int. That is you, can not create arrays that are larger than Integer.MAX_VALUE (2147483647), probably a few elements less (depending on the VM). You can cast your value to int

    arr = new long[(int)(y+1)];
    

    but this will produce invalid results when the value of y is actually larger than the maximum allowed size.

提交回复
热议问题