Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在数组中搜索空槽_Java_Arrays_Parseint - Fatal编程技术网

Java 在数组中搜索空槽

Java 在数组中搜索空槽,java,arrays,parseint,Java,Arrays,Parseint,我正在尝试搜索数组中的第一个空插槽。你能用引号来做这件事吗,或者我会用“stobar[b]==null” int[]stobar=newint[100]; for(int b=0;b

我正在尝试搜索数组中的第一个空插槽。你能用引号来做这件事吗,或者我会用“
stobar[b]==null

int[]stobar=newint[100];
for(int b=0;b
这两种方法都不能按您想要的方式工作,因为您有一个只能保存整数的primative数组。如果您想要一个不同的空值,则需要将其改为
整数[]

这两种方法都不能按您想要的方式工作,因为您有一个只能保存整数的primative数组。如果需要一个不同的空值,则需要将其设置为
整数[]

可以使用

Integer[] stobar = new Integer[100];
...

for(int b=0; b<stobar.length; b++ )
{
    if(stobar[b]==null)
    {
      stobar[b] = row;
      stobar[b+1] = col;
      break;
    }
}
Integer[]stobar=新整数[100];
...
对于(intb=0;b您可以使用

Integer[] stobar = new Integer[100];
...

for(int b=0; b<stobar.length; b++ )
{
    if(stobar[b]==null)
    {
      stobar[b] = row;
      stobar[b+1] = col;
      break;
    }
}
Integer[]stobar=新整数[100];
...

对于(int b=0;b注意,此示例不可能是自包含的:如果您在一行上初始化整个数组,并在下一行上对其进行迭代,则每个单元格中都会有默认值。Integer的默认值为“null”,而int的默认值为“0”。请注意,此示例不可能是自包含的:如果您初始化在一行上调整整个数组的大小,并在下一行上对其进行迭代,则每个单元格中始终具有默认值。Integer的默认值为“null”,而int的默认值为“0”。
public class Point
{
  private int row;
  private int col;

  public Point(int row, int col)
  {
    this.row = row;
    this.col = col;
  }

  public static void main(String[] args)
  {
    List<Point> points = new ArrayList<Point>();

    ...
    Point p = new Point(5,8);
    points.add(p);
    ...
  }

}