Topics
Published on February 19, 2018 by ProgrammingKnowledge

In this video we will cover the basic syntax and capabilities of Lists in Scala.
Arrays and Lists
Arrays are a fixed length and occupy sequential locations in memory. This makes random access (for example, getting the 37th element) very fast–O(1) .
Lists are composed of values linked together. All access starts from the head (first element) and follows links. Random access takes linear time.
Lists are immutable
Lists, like Strings, are immutable
Because all access is via the head, creating a “new” list is a fast operation.
List operations
Basic fast (constant time) operations
list.head (or list head) returns the first element in the list
list.tail (or list tail) returns a list with the first element removed
value :: list returns a list with value appended to the front
list.isEmpty (or list isEmpty ) tests whether the list is empty
Some slow (linear time) operations
list(i) returns the ith element (starting from 0) of the list
list.last (or list last) returns the last element in the list
list.init (or list init) returns a list with the last element removed
This involves making a complete copy of the list
list.length (or list length) returns the number of elements in the list
list.reverse (or list reverse) returns a new list with the elements in reverse order
In practice, the slow operations are hardly ever needed

———————-Follow——————-
My Website – www.codebind.com
My Blog – goo.gl/Nd2pFn
My Facebook Page – goo.gl/eLp2cQ
Google+ – goo.gl/lvC5FX
Twitter – twitter.com/ProgrammingKnow
Pinterest – goo.gl/kCInUp
Text Case Converter – goo.gl/pVpcwL
Epoch Timestamp Converter – goo.gl/Zedjo5
Decimal – Binary – Hexadecimal Converter – goo.gl/rkX3JE
8-bit Checksum Calculator – goo.gl/inxvIT
————————-Stuff I use to make videos ——————-
Stuff I use to make videos
Windows notebook – amzn.to/2zcXPyF
Apple MacBook Pro – amzn.to/2BTJBZ7
Desktop – amzn.to/2zct252
Microphone – amzn.to/2zcYbW1
notebook mouse – amzn.to/2BVs4Q3

Leave a Reply

4 Comments on "Scala Tutorial 19 – Lists"

Notify of
avatar

Ayid Idevirt
Guest
Ayid Idevirt
3 months 29 days ago
Arti Gupta
Guest
Arti Gupta
4 months 4 days ago

Wow nice video

techmefast
Guest
techmefast
4 months 4 days ago

sir please tell some visual basic programmes

COMPUTERGURUJI GAMING
Guest
COMPUTERGURUJI GAMING
4 months 4 days ago

Sir you are the guy jisse Maine programming languages sikhi.Plzz sir Ek request Android game development in Andy studio

wpDiscuz