Home » » Scala Tutorial Nineteen - Lists

Scala Tutorial Nineteen - Lists



In this video nosotros volition encompass the basic syntax as well as capabilities of Lists inwards Scala.

Arrays as well as Lists

Arrays are a fixed length as well as occupy sequential locations inwards memory. This makes random access (for example, getting the 37th element) real fast--O(1) .

Lists are composed of values linked together. All access starts from the caput (first element) as well as follows links. Random access takes linear time.

Lists are immutable

Lists, similar Strings, are immutable

Because all access is via the head, creating a “new” listing is a fast operation.

List operations

Basic fast (constant time) operations

list.head (or listing head) returns the kickoff chemical ingredient inwards the list

list.tail (or listing tail) returns a listing amongst the kickoff chemical ingredient removed

value :: listing returns a listing amongst value appended to the front

list.isEmpty (or listing isEmpty ) tests whether the listing is empty

Some tedious (linear time) operations

list(i) returns the ith chemical ingredient (starting from 0) of the list

list.last (or listing last) returns the final chemical ingredient inwards the list

list.init (or listing init) returns a listing amongst the final chemical ingredient removed

This involves making a consummate re-create of the list

list.length (or listing length) returns the seat out of elements inwards the list

list.reverse (or listing reverse) returns a novel listing amongst the elements inwards contrary order

In practice, the tedious operations are hardly e'er needed



----------------------Follow-------------------

My Website - http://www.codebind.com

My Blog - https://goo.gl/Nd2pFn

My Facebook Page - https://goo.gl/eLp2cQ

Google+ - https://goo.gl/lvC5FX

Twitter - https://twitter.com/ProgrammingKnow

Pinterest - https://goo.gl/kCInUp

Text Case Converter - https://goo.gl/pVpcwL

Epoch Timestamp Converter - https://goo.gl/Zedjo5

Decimal - Binary - Hexadecimal Converter - https://goo.gl/rkX3JE

8-bit Checksum Calculator - https://goo.gl/inxvIT

-------------------------Stuff I role to brand videos -------------------

Stuff I role to brand videos

Windows notebook – http://amzn.to/2zcXPyF

Apple MacBook Pro – http://amzn.to/2BTJBZ7

Desktop - http://amzn.to/2zct252

Microphone – http://amzn.to/2zcYbW1

notebook mouse – http://amzn.to/2BVs4Q3

0 comments:

Post a Comment

Search

Blog Archive