11
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Dartの配列(List)どうしの比較(忘備録)

Last updated at Posted at 2020-10-11

DartのListはそのままだと比較できないのでその比較方法です。

  List listA = [1, 2, 3];
  List listB = [1, 2, 3];
  print(listA == listB); // false

方法1:foundation.dartを使う

import

import 'package:flutter/foundation.dart'; 

listEqualsを使う

  List listA = [1, 2, 3];
  List listB = [1, 2, 3];
  print(listEquals(listA, listB)); // true

方法2:collection.dartを使う

import

import 'package:collection/collection.dart'; 

※標準packageなのでpubspec.yamlなどへの追加は不要です

ListEquality().equalsを使う

  List listA = [1, 2, 3];
  List listB = [1, 2, 3];
  Function isEqual = const ListEquality().equals;
  print(isEqual(listA, listB)); // true

参照

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?