Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home for dartlang.org
« Groups Home
ArrayList equivalent?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  15 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mehmet Akin  
View profile  
 More options Apr 12 2012, 7:01 am
From: Mehmet Akin <mda...@gmail.com>
Date: Thu, 12 Apr 2012 04:01:35 -0700 (PDT)
Local: Thurs, Apr 12 2012 7:01 am
Subject: ArrayList equivalent?
Hi,

Is there an equivalent of Java's ArrayList in Dart?
Namely, I need a growable list which has these methods:

- size() method that returns the number of objects it holds.
- add(int index, E element) => inserts an element to a location,
shifts subsequent elements to right.

Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Allan MacDonald  
View profile  
 More options Apr 12 2012, 7:31 am
From: Allan MacDonald <amacdon...@cgsinc.ca>
Date: Thu, 12 Apr 2012 08:31:34 -0300
Local: Thurs, Apr 12 2012 7:31 am
Subject: Re: [misc] ArrayList equivalent?

Hi,

The one I use is Interface List<E>, where length would be equivalent to
size() in Java, and  cars.insertRange(1, 1, 'Ranger') would be used where
you would use add(int index, E element) in java.

List<String> cars = new List<String>();
cars.

  List<String> cars = new List<String>();
  cars.add('Chevette');
  cars.add('Corolla');
  cars.add('Jetta');
  cars[0] = 'Corvette';//replace a value at 0
  cars.insertRange(1, 1, 'Ranger');
  print('there are ${cars.length} cars. Car at index 1 is the ${cars[1]}');

This prints out;

there are 4 cars. Car at index 1 is the Ranger

Allan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ladislav Thon  
View profile  
 More options Apr 12 2012, 7:32 am
From: Ladislav Thon <ladi...@gmail.com>
Date: Thu, 12 Apr 2012 13:32:10 +0200
Local: Thurs, Apr 12 2012 7:32 am
Subject: Re: [misc] ArrayList equivalent?

> Is there an equivalent of Java's ArrayList in Dart?

Yes, it's called List (http://api.dartlang.org/dart_core/List.html).

> - size() method that returns the number of objects it holds.

The length property.

> - add(int index, E element) => inserts an element to a location,
> shifts subsequent elements to right.

Strictly speaking, there is no such method (and I hope that it will be),
but insertRange is capable of doing it (and more).

LT


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mehmet Akin  
View profile  
 More options Apr 12 2012, 7:38 am
From: Mehmet Akin <mda...@gmail.com>
Date: Thu, 12 Apr 2012 04:38:41 -0700 (PDT)
Local: Thurs, Apr 12 2012 7:38 am
Subject: Re: ArrayList equivalent?
Hi,

On Apr 12, 1:32 pm, Ladislav Thon <ladi...@gmail.com> wrote:

> > Is there an equivalent of Java's ArrayList in Dart?

> Yes, it's called List (http://api.dartlang.org/dart_core/List.html).

> > - size() method that returns the number of objects it holds.

> The length property.

Maybe i am missing something but It seems length is the number of
slots in the list, which is the equivalent of elementData.length in
Java Arraylist, not size of List.

> > - add(int index, E element) => inserts an element to a location,
> > shifts subsequent elements to right.

> Strictly speaking, there is no such method (and I hope that it will be),
> but insertRange is capable of doing it (and more).

Ok insertRange looks ok, though as you said, I would prefer a simpler
method.

> LT

Thanks

Mehmet


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ladislav Thon  
View profile  
 More options Apr 12 2012, 7:41 am
From: Ladislav Thon <ladi...@gmail.com>
Date: Thu, 12 Apr 2012 13:41:53 +0200
Local: Thurs, Apr 12 2012 7:41 am
Subject: Re: [misc] Re: ArrayList equivalent?

> > > - size() method that returns the number of objects it holds.

> > The length property.

> Maybe i am missing something but It seems length is the number of
> slots in the list, which is the equivalent of elementData.length in
> Java Arraylist, not size of List.

Very unlikely. I can't test now, but I'm pretty sure I already used
List.length and it works as expected. See more at
http://api.dartlang.org/dart_core/Collection.html#get:length

LT


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Allan MacDonald  
View profile  
 More options Apr 12 2012, 7:47 am
From: Allan MacDonald <amacdon...@cgsinc.ca>
Date: Thu, 12 Apr 2012 08:47:14 -0300
Local: Thurs, Apr 12 2012 7:47 am
Subject: Re: [misc] Re: ArrayList equivalent?

I believe you can increase the size of a List, and each additional element
will be assigned null by default. In this case, length would include all
null values as well.

Allan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mehmet Akin  
View profile  
 More options Apr 12 2012, 7:55 am
From: Mehmet Akin <mda...@gmail.com>
Date: Thu, 12 Apr 2012 04:55:25 -0700 (PDT)
Local: Thurs, Apr 12 2012 7:55 am
Subject: Re: ArrayList equivalent?
Hi,

On Apr 12, 1:41 pm, Ladislav Thon <ladi...@gmail.com> wrote:

> > > > - size() method that returns the number of objects it holds.

> > > The length property.

> > Maybe i am missing something but It seems length is the number of
> > slots in the list, which is the equivalent of elementData.length in
> > Java Arraylist, not size of List.

> Very unlikely. I can't test now, but I'm pretty sure I already used
> List.length and it works as expected. See more athttp://api.dartlang.org/dart_core/Collection.html#get:length

> LT

Ok, you are right , it seems I messed up something else. I guess this
is the default growable list implementation:
http://code.google.com/p/dart/source/browse/trunk/dart/runtime/lib/gr...

Thanks everyone answered.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ladislav Thon  
View profile  
 More options Apr 12 2012, 8:03 am
From: Ladislav Thon <ladi...@gmail.com>
Date: Thu, 12 Apr 2012 14:03:11 +0200
Local: Thurs, Apr 12 2012 8:03 am
Subject: Re: [misc] Re: ArrayList equivalent?

> I believe you can increase the size of a List,

Sure you can.

> and each additional element will be assigned null by default.

It will.

> In this case, length would include all null values as well.

Doh! I didn't think about that. My intuition tells me that it shouldn't,
but on the other hand, what if you explicitly want to have nulls at the end
of the list... I'll have to test that. Thanks for pointer!

LT


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
afsina  
View profile  
 More options Apr 12 2012, 8:10 am
From: afsina <ahme...@gmail.com>
Date: Thu, 12 Apr 2012 05:10:41 -0700 (PDT)
Local: Thurs, Apr 12 2012 8:10 am
Subject: Re: ArrayList equivalent?

On Apr 12, 2:47 pm, Allan MacDonald <amacdon...@cgsinc.ca> wrote:

> I believe you can increase the size of a List, and each additional element
> will be assigned null by default. In this case, length would include all
> null values as well.

> Allan

Indeed, from the documentation Dart Lists seems like a growable array.
There is no dictinction of length and capacity. Every insertion makes
the array length 1 more. And you can explicitly extend the length.
This gives more control in some cases but a distinction of length and
capacity would prevent some bugs (NPEs).


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mehmet Akin  
View profile  
 More options Apr 12 2012, 8:35 am
From: Mehmet Akin <mda...@gmail.com>
Date: Thu, 12 Apr 2012 05:35:47 -0700 (PDT)
Local: Thurs, Apr 12 2012 8:35 am
Subject: Re: ArrayList equivalent?

On Apr 12, 2:10 pm, afsina <ahme...@gmail.com> wrote:

> On Apr 12, 2:47 pm, Allan MacDonald <amacdon...@cgsinc.ca> wrote:

> > I believe you can increase the size of a List, and each additional element
> > will be assigned null by default. In this case, length would include all
> > null values as well.

> > Allan

> Indeed, from the documentation Dart Lists seems like a growable array.
> There is no dictinction of length and capacity. Every insertion makes
> the array length 1 more. And you can explicitly extend the length.
> This gives more control in some cases but a distinction of length and
> capacity would prevent some bugs (NPEs).

Actually if you construct the list with inital length it is fixed
length; Otherwise it is growable. (Explained here:
http://blog.sethladd.com/2011/12/lists-and-arrays-in-dart.html).

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Allan MacDonald  
View profile  
 More options Apr 12 2012, 8:41 am
From: Allan MacDonald <amacdon...@cgsinc.ca>
Date: Thu, 12 Apr 2012 09:41:23 -0300
Local: Thurs, Apr 12 2012 8:41 am
Subject: Re: [misc] Re: ArrayList equivalent?

Ah, yes. This is a good point.

Allan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Allan MacDonald  
View profile  
 More options Apr 12 2012, 8:50 am
From: Allan MacDonald <amacdon...@cgsinc.ca>
Date: Thu, 12 Apr 2012 09:50:09 -0300
Local: Thurs, Apr 12 2012 8:50 am
Subject: Re: [misc] Re: ArrayList equivalent?

On Thu, Apr 12, 2012 at 9:41 AM, Allan MacDonald <amacdon...@cgsinc.ca>wrote:

On further examination, it appears that you can set existing list index
variables to null.  I suppose this is equivalent to ArrayList in Java since
it will too accept null values.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
evan chua-yap  
View profile  
 More options Apr 12 2012, 1:55 pm
From: evan chua-yap <semweb...@gmail.com>
Date: Thu, 12 Apr 2012 10:55:09 -0700 (PDT)
Local: Thurs, Apr 12 2012 1:55 pm
Subject: Re: ArrayList equivalent?
Does anyone know if List has the equivalent of addAll(index,
collection)
for adding all the items in an existing collection to a list object at
the specified index?

List list = [1, 5, 9];
list.addAll(1, [2,3,4]);
print(list);  // should print [1,2,3,4,5,9]

insertRange and setRange don't seem to do it.
I tried searching the open issues (advanced search , with words ...),
but I didn't get hits.

Thanks!

evan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bob Nystrom  
View profile  
 More options Apr 12 2012, 2:04 pm
From: Bob Nystrom <rnyst...@google.com>
Date: Thu, 12 Apr 2012 11:04:42 -0700
Local: Thurs, Apr 12 2012 2:04 pm
Subject: Re: [misc] Re: ArrayList equivalent?

On Thu, Apr 12, 2012 at 10:55 AM, evan chua-yap <semweb...@gmail.com> wrote:
> Does anyone know if List has the equivalent of addAll(index,
> collection)
> for adding all the items in an existing collection to a list object at
> the specified index?

> List list = [1, 5, 9];
> list.addAll(1, [2,3,4]);
> print(list);  // should print [1,2,3,4,5,9]

> insertRange and setRange don't seem to do it.
> I tried searching the open issues (advanced search , with words ...),
> but I didn't get hits.

It doesn't seem to. I'm surprised insertRange() doesn't do this, but it
looks like it doesn't. Soon, Josh is going to refresh our collection
libraries and I'm 100% certain that this will be a supported operation when
he does.

- bob


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joshua Bloch  
View profile  
 More options Apr 12 2012, 2:10 pm
From: Joshua Bloch <j...@google.com>
Date: Thu, 12 Apr 2012 11:10:21 -0700
Local: Thurs, Apr 12 2012 2:10 pm
Subject: Re: [misc] Re: ArrayList equivalent?

Yep.  I've been very busy with the leadup to next week's trial (Oracle v.
Google; looks like I'll be testifying early in the week, and then again the
week after).  But I will get this done as soon as possible.

    Josh


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »