LoginSignup
1
0

More than 5 years have passed since last update.

配列に代入演算するとnull値が入ってしまう

Last updated at Posted at 2017-01-02

配列を生成したときに初期値を設定していないと
配列にnullが入ってしまった。
【コード】

String[] c = new String[4];
c[1] += 3;
System.out.println(c[1]);

【出力結果】
null3

配列の全要素に初期値を設定するためには以下を追加したら、
nullが入らなかった。

Arrays.fill(c, "");
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0