lasy, and all other collections are static (Eager) loaded. But you can easily convert a static collection to lazy, which is to create a view.Collection type OverviewImmutable Collectionimmutable SeqSeq is divided into two main categories: indexed sequences and linear sequences,indexed sequences imply that this collection has a higher performance in random reads (similar to arrays in data structures). Linea
Key points in this chapter
All collections are extended from iterable traits
There are three main classes of collections: sequence, set, map
Scala provides both mutable and immutable versions for almost all collection classes
The Scala list is either empty or has a tail, where the trailer itself is a list
Set is a set of no precedence
One, there are several concepts that you must know when using the Scala collection:
1. What is a predicate?
A predicate is a method, a function or an anonymous function that takes one or more functions and returns a Boolean value.
For example: The following method returns TRUE or FALSE, so it is a predicate.
if true Else false IsEven: (i:int) Boolean
2. What is an anonymous function?
An anonymous function i
Package Com.xing.listfile/** * Created by Dengni on 2017/2/11. */class Dataframework case Class Computationframework (Val name:string,val age:int) extends Dataframework case class Stor
Ageframework (name:string, Age:int) extends Dataframework object Hellopatternmatch {def main (args:array[string]) { Pattern matching pair value matching getsalary ("Spark") getsalary ("Spark1") getsalary ("Spark",) getsalary ("Spark1", 16)/ /pattern matching pairs of data types Getmatchtype () getmatchtype ("
Scala is one of the most powerful programming languages in the field of data mining algorithms, and the language itself is function oriented, which also conforms to the common scenarios of data mining algorithms: Applying a series of transformations on the original data set, the language itself also provides many powerful functions for the collection operation, this article will take the list type as an exa
Scala is one of the most powerful programming languages in the field of data mining algorithms, language itself is a function-oriented, which also conforms to the common scene of data mining algorithms: The use of a series of transformations on the original dataset, the language itself also provides a number of powerful functions of the set operation, this article will be the list type as an example, Describes common
One: IP-to-digital, used in the range of the IP segment for a specific size def ip2long (ip:string): Long = { = Ip.split ("[.]" ) = 0L for (i until fragments.length) { = fragments (i). Tolong | Ipnum } ipnum }Two: dichotomy to find a range of IP segment def binarysearch (lines:array[(long, Long, String)], Ip:long): Int = { = 0 = lines.length-1 while (Low ) { = (low + high)/2 if (IP >= lines (middle). _1) (IP lines (middle). _2)) return Middl
Scala is one of the most powerful programming languages in the field of data mining algorithms, language itself is a function-oriented, which also conforms to the common scene of data mining algorithms: The use of a series of transformations on the original dataset, the language itself also provides a number of powerful functions of the set operation, this article will be the list type as an example, Describes common
+ method, the operator is overloaded the to operation can generate an interval set 2.4 branch statements
scala> var x=3
x:int = 3
scala> if (x
scala> var x=10
x:int = ten
scala> if (x
2.4 Circular Statements
(1) while Loop
scala> var i=1
i:int = 1
languages, and even experienced programmers need to know this part of the text carefully.In Scala, there is no for (initialize; test; update) for loop, and to implement related functions, either use the while instead, or use the Scala for statement for (i .3.1. Iteration 3.1.1 for collections. Basic syntaxA for statement that iterates over a collection, in the
First, Scala overviewcan expand? Object Oriented? function-type programming compatible with Java Interop Syntax concise ? code line short ? ? abstract control statically typed can examine secure refactoring support concurrency control Customize other control structures Ii. installation of ScalaIdeEclipse (native support, use more complex)IntelliJ (expensive)NetBeans
Scala basic syntax
If you have a good understanding of the Java language, it will be easy to learn Scala. The most important difference between Scala and Java is that the line terminator is optional. Consider a Scala program that can be defined as a collection of objects tha
" -> 3) // 创建一个顺序的Mapmonths += ("Fourth" -> 4)println("months=> " + months) // months=> Map(January -> 1, February -> 2, March -> 3, Fourth -> 4)Tuple tuple definitionsA map is a collection of key/value duality. Duality is the simplest form of tuple (tuple), which is the aggregation of different types of values. The value of a tuple is formed by enclosing a single value in parentheses. For example:(1, 3.14, "Fred")is a tuple that is of type:Tuple
Tags: nbsp idea Big Data development GTK Target 1.3 website startup technology sharingStep Two: Install IntelliJ idea If 3 nodes such as Master, Slave1, Slave2, it is recommended to install it on the master nodeTo Https://www.jetbrains.com/idea download the corresponding version of the file,Because, I usually install the JDK myself, without the openjdk of CentOS, so I download the version as followsThen unzip it.The following is the directory where IntelliJ idea was installedThen proceed to the
Implicit references (implicit Import)Scala automatically adds several implicit references to each program, just as the Java program automatically adds a Java.lang package. In Scala, the contents of the following three packages are implicitly referenced to each program. The difference is that Scala also implicitly adds a reference to the Predef, which greatly faci
Scala tutorial, scala Programming
The following is a complete scala getting started tutorial I have collected from the Internet. I have followed other programming basics to get started.
Compared with other languages such as Java, Scala is a complex language. It is a unity of object-oriented and function-oriented. It is
This course focuses onSpark, the hottest, most popular and promising technology in the big Data world today. In this course, from shallow to deep, based on a large number of case studies, in-depth analysis and explanation of Spark, and will contain completely from the enterprise real complex business needs to extract the actual case. The course will cover Scala programming, spark core programming, spark SQL and spark streaming, spark kernel and source
, Math.exp (1))
}
Abstract class
You can define an abstract class that defines some methods but does not implement them. Instead, these methods are defined by the subclass of the extended abstract class. You cannot create an instance of an abstract class.
Scala> abstract class Shape {
| Def getarea (): Int //subclass should define this
|}
Defined class Shape
scala> class Circle (r:int) exte
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.