0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Java】5分で読めるListの基本知識

Posted at

Listを一言で説明

可変長の配列のこと
要素数を指定せずに宣言する。

Listの特徴

Listはインタフェースのため、実装クラスを使用する
実装クラスの例

  • ArrayList:可変長配列で読み書きを高速に行える
  • LinkedList:双方向連結リストで挿入や削除に強い

Listの基本操作

  1. 要素の追加 add()
  2. 要素の削除 remove() (→deleteは×)
  3. 要素の取得 get()
  4. 要素数の取得 size()
  5. 要素の存在チェック contains()
  6. 要素の空チェック isEmpty()
  7. 要素を全て削除 clear()
List<String> fruits = new ArrayList<>();
fruits.add("Apple"); // 1.要素の追加
fruits.add("Banana");
System.out.println(fruits.get(0)); // 3.要素の取得 Apple
fruits.remove("Apple") // 2.要素の削除
System.out.println(fruits.size()); // 4.要素数の取得 1
System.out.println(fruits.contains("Banana")); // 5.要素の存在チェック true
fruits.clear(); // 7.要素を全て削除
System.out.println(fruits.isEmpty()); // 6.要素の空チェック true

記事作成時間:20分

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?