我怎么可以看到,如果在一个int数组中的元素是空的? [英] How can I see if an element in an int array is empty?

查看:269
本文介绍了我怎么可以看到,如果在一个int数组中的元素是空的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

我想看看数组[5] 持有的值或为空。

I want to see if array[5] holds a value or is empty.

推荐答案

在基本数组元素不能为空。他们将永远得到初始化的东西(一般 0 INT 阵列,而是取决于你如何声明数组)

Elements in primitive arrays can't be empty. They'll always get initialized to something (usually 0 for int arrays, but depends on how you declare the array).

如果您声明数组像这样(例如):

If you declare the array like so (for example):

int [] myArray ;
myArray = new int[7] ;

然后所有的元素将默认为 0

有关声明数组的另一种语法是

An alternative syntax for declaring arrays is

int[] myArray = { 12, 7, 32, 15, 113, 0, 7 };

凡(在这种情况下,大小七)数组的初始值在大括号中给出 {}

这篇关于我怎么可以看到,如果在一个int数组中的元素是空的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆