I want new List() to have a parameter 'growable'.

72 views
Skip to first unread message

Suguru Inatomi

unread,
Oct 24, 2014, 1:15:36 AM10/24/14
to mi...@dartlang.org
When I want a growable list whose length is 10,

Now

var list = new List()..length = 10;
or
var list = []..length = 10;

But I want to define the length in the constructor.

var list = new List(10, growable: true);

thanks.

Seth Ladd

unread,
Oct 24, 2014, 11:48:43 AM10/24/14
to General Dart Discussion
Would `new List.from(new List(10))` work for you?


--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.

Matthew Butler

unread,
Oct 24, 2014, 12:03:40 PM10/24/14
to mi...@dartlang.org
Alternatively:

new List.generate(10, (_) => null, growable: true);

Filipe Morgado

unread,
Oct 24, 2014, 2:18:12 PM10/24/14
to mi...@dartlang.org
Would this work?

final list = new List()..length = 10;

Suguru Inatomi

unread,
Oct 24, 2014, 8:41:39 PM10/24/14
to mi...@dartlang.org
I think Dart is like Java. In Java, "new ArrayList(10)" gives a growable list.
List of Dart is defined the single abstract class "List". I cannot detect that list is growable in my editor. So, I want to define fixed-length list explicitly.
Reply all
Reply to author
Forward
0 new messages