This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Turning an array into a list

3 replies
Kenneth McDonald
Joined: 2009-01-11,
User offline. Last seen 42 years 45 weeks ago.

Is there any built-in way to produce a list from an array? Or does one
have to construct the list element by element, generating many
intermediate lists that will be thrown out.

Thanks,
Ken

David Pollak
Joined: 2008-12-16,
User offline. Last seen 42 years 45 weeks ago.
Re: Turning an array into a list
You mean like:
Array(1,2,3).toList
? ;-)

On Sun, Jan 11, 2009 at 1:09 PM, Kenneth McDonald <kenneth [dot] m [dot] mcdonald [at] sbcglobal [dot] net> wrote:
Is there any built-in way to produce a list from an array? Or does one have to construct the list element by element, generating many intermediate lists that will be thrown out.

Thanks,
Ken



--
Lift, the simply functional web framework http://liftweb.net
Collaborative Task Management http://much4.us
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp
Joshua.Suereth
Joined: 2008-09-02,
User offline. Last seen 32 weeks 5 days ago.
Re: Turning an array into a list
and if you mean a Java List...

Arrays.asList( scalaArray : _* )

Note: I believe you have to import java.util.Arrays or something like that.

-Josh

On Sun, Jan 11, 2009 at 4:11 PM, David Pollak <feeder [dot] of [dot] the [dot] bears [at] gmail [dot] com> wrote:
You mean like:
Array(1,2,3).toList
? ;-)

On Sun, Jan 11, 2009 at 1:09 PM, Kenneth McDonald <kenneth [dot] m [dot] mcdonald [at] sbcglobal [dot] net> wrote:
Is there any built-in way to produce a list from an array? Or does one have to construct the list element by element, generating many intermediate lists that will be thrown out.

Thanks,
Ken



--
Lift, the simply functional web framework http://liftweb.net
Collaborative Task Management http://much4.us
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

Victor NOEL
Joined: 2008-12-21,
User offline. Last seen 42 years 45 weeks ago.
Re: Turning an array into a list

On Sun, Jan 11, 2009 at 03:09:30PM -0600, Kenneth McDonald wrote:
> Is there any built-in way to produce a list from an array? Or does one
> have to construct the list element by element, generating many
> intermediate lists that will be thrown out.

Hi,

Just to clarify :
when you use a list to create another one (with a new head),
nothing is thrown out ! The first list IS the tail.

>
> Thanks,
> Ken

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland