简体   繁体   English

Java多维数组/打印空值

[英]Java multi dimension array/ printing null values

This is from an array with 10 rows 4 columns.这是来自一个 10 行 4 列的数组。 How do I get the if to keep the null values from printing to screen如何获得 if 以防止空值打印到屏幕

      for(int j = 0; j < calculation[i].length; j++)
        if (calculation[i] != null)<-------- this does nothing, however if I change it to == null nothing prints to screen
      System.out.print(calculation[i][j] + " \t");
      System.out.print("\n");

This will print the entire array for you except for the null values.这将为您打印整个数组,除了空值。

  for(int i = 0; i < calculation.length; i++)
    {
      for(int j = 0; j < calculation[i].length; j++)
      {
        if(calculation[i][j] != null)
           System.out.println(calculation[i][j] + "\t");
      }
      System.out.println("");
    }

calculation[i] may not be null but calculation[i][j] could be. calculation[i]可能不为空,但calculation[i][j]可能为空。

Change your code to:将您的代码更改为:

if (calculation[i][j] != null) 
      {
   //Your code.
      }    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM