LoginSignup
2
0

More than 3 years have passed since last update.

<Java>固定長(行)*可変長(列)の二次元配列を作る場合

Last updated at Posted at 2018-05-26

始めに

とりあえずこの前気づいたことをメモ。
検索してもなかなか出てこなかったから・・・

可変長の列は、どれくらいになるかは定かではない前提。

実装

Sample.java
//定義 -- 50行は固定
ArrayList[] list = new ArrayList[50]

for(int i = 0;i < 50;i++){
  list[i] = new ArrayList(); //ここで可変長の列を作る
}
Sample.java
//行にアイテムを追加する(列の追加)  
list[3].add("apple"); //これで1列プラス

//指定した行から、任意の列の値を取得する。
list[3].get(4) //3行目の4列目のデータを取得
2
0
1

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
2
0