LoginSignup
0
0

More than 3 years have passed since last update.

[Java] removeAll()の使い方

Posted at

使用法

[1, 2, 3, 2, 5] から 25 を削除したい場合、removeAllで以下のように実装できる。

        List<Integer> list = new ArrayList<>();
        list.add(1); list.add(2); list.add(3); list.add(2); list.add(5);
        System.out.println(list);  //=> [1, 2, 3, 2, 5]
        System.out.println(list.removeAll(Arrays.asList(2, 5)));  //=> true
        System.out.println(list);  //=> [1, 3]

注意点

list.removeAll(2) のように要素を直接渡すことはできない。(コンパイルエラー)

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