3
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?

More than 3 years have passed since last update.

Dart(Flutter)で2つの配列を結合する

Posted at

概要

例えばJavaScriptでの、Array.prototype.concat()のように2つの配列を結合して返すようなメソッドがDartであるか。やりたいことはシンプルなのですが、日本語だとなかなかドンピシャの記事がなくて、少し探すのに苦労したのでメモ書きとして残しておきます。

対応

How do I combine two lists in Dart?の記事に色々と方法が書いてあるのですが、Dart2以降であれば+記号を使うことで結合ができるので、これが一番シンプルな書き方かなと思います。以下のような感じで元の配列に影響を与えず、結合後の配列を取得することが可能です。

sample.dart
var list1 = [1, 2, 3];
var list2 = [4, 5, 6];

var newList = list1 + list2;

3
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
3
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?