More than 5 years have passed since last update.
二次元配列[i][j]において、iは固定長でjが可変長な二次元配列を作る方法。
簡単に表すとこんな感じ
1 2 3 4 5 6 7 8 9
1 - - - - - - -
2 - - -
3 - - - - - - - - -
4 - -
5 - - - - - -
縦がi,横がj,-が配列の各要素
流れ的には
①二次元配列[5][]を作る
②ArrayListを使って、i行目の可変長部分を取得
③ArrayListから配列に戻す
実際にはこんな感じ
①String[][] s = new String[5][]
②ArrayList list = new ArrayList();
でリストを定義
list.add("")をi行目のj分だけfor文で回す
③String[i] s = (String[])list.toArray(new String[0]);
をiの数だけfor文でまわす
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
