Skip to content

Commit 48a2784

Browse files
prep
1 parent 3ce4ae7 commit 48a2784

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+29982
-22
lines changed

pom.xml

+11-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,17 @@
6161
<artifactId>delta-core_2.11</artifactId>
6262
<version>0.6.1</version>
6363
</dependency>
64-
64+
<dependency>
65+
<groupId>org.apache.spark</groupId>
66+
<artifactId>spark-avro_2.11</artifactId>
67+
<version>2.4.0</version>
68+
</dependency>
69+
<!-- https://mvnrepository.com/artifact/com.databricks/spark-xml -->
70+
<dependency>
71+
<groupId>com.databricks</groupId>
72+
<artifactId>spark-xml_2.10</artifactId>
73+
<version>0.4.1</version>
74+
</dependency>
6575

6676
</dependencies>
6777

resources/hcsc/hi.xml

+453
Large diffs are not rendered by default.

resources/hcsc/hl.xml

+27,560
Large diffs are not rendered by default.

resources/interview/test.csv

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
12,34,56
2+
23,56,86,87
3+
45,67,56
4+
56,77,66

resources/interview/testcases.csv

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
date,World,Afghanistan,Albania,Algeria,Andorra,Angola,Anguilla,Antigua and Barbuda,Argentina,Armenia,Aruba,Australia,Austria,Azerbaijan,Bahamas,Bahrain,Bangladesh,Barbados,Belarus,Belgium,Belize,Benin,Bermuda,Bhutan,Bolivia,Bonaire Sint Eustatius and Saba,Bosnia and Herzegovina,Botswana,Brazil,British Virgin Islands,Brunei,Bulgaria,Burkina Faso,Burundi,Cambodia,Cameroon,Canada,Cape Verde,Cayman Islands,Central African Republic,Chad,Chile,China,Colombia,Congo,Costa Rica,Cote d'Ivoire,Croatia,Cuba,Curacao,Cyprus,Czech Republic,Democratic Republic of Congo,Denmark,Djibouti,Dominica,Dominican Republic,Ecuador,Egypt,El Salvador,Equatorial Guinea,Eritrea,Estonia,Ethiopia,Faeroe Islands,Falkland Islands,Fiji,Finland,France,French Polynesia,Gabon,Gambia,Georgia,Germany,Ghana,Gibraltar,Greece,Greenland,Grenada,Guam,Guatemala,Guernsey,Guinea,Guinea-Bissau,Guyana,Haiti,Honduras,Hungary,Iceland,India,Indonesia,International,Iran,Iraq,Ireland,Isle of Man,Israel,Italy,Jamaica,Japan,Jersey,Jordan,Kazakhstan,Kenya,Kosovo,Kuwait,Kyrgyzstan,Laos,Latvia,Lebanon,Liberia,Libya,Liechtenstein,Lithuania,Luxembourg,Macedonia,Madagascar,Malawi,Malaysia,Maldives,Mali,Malta,Mauritania,Mauritius,Mexico,Moldova,Monaco,Mongolia,Montenegro,Montserrat,Morocco,Mozambique,Myanmar,Namibia,Nepal,Netherlands,New Caledonia,New Zealand,Nicaragua,Niger,Nigeria,Northern Mariana Islands,Norway,Oman,Pakistan,Palestine,Panama,Papua New Guinea,Paraguay,Peru,Philippines,Poland,Portugal,Puerto Rico,Qatar,Romania,Russia,Rwanda,Saint Kitts and Nevis,Saint Lucia,Saint Vincent and the Grenadines,San Marino,Sao Tome and Principe,Saudi Arabia,Senegal,Serbia,Seychelles,Sierra Leone,Singapore,Sint Maarten (Dutch part),Slovakia,Slovenia,Somalia,South Africa,South Korea,South Sudan,Spain,Sri Lanka,Sudan,Suriname,Swaziland,Sweden,Switzerland,Syria,Taiwan,Tanzania,Thailand,Timor,Togo,Trinidad and Tobago,Tunisia,Turkey,Turks and Caicos Islands,Uganda,Ukraine,United Arab Emirates,United Kingdom,United States,United States Virgin Islands,Uruguay,Uzbekistan,Vatican,Venezuela,Vietnam,Zambia,Zimbabwe

resources/movies.csv

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
movie,title,genres,year,Rating,Rotton Tomato
22
108583,Fawlty Towers (1975,Comedy,-1980,1,54
3+
,Goal,,1,0,
34
32898,"Trip to the Moon, A (Voyage dans la lune, Le)",Action|Adventure|Fantasy|Sci-Fi,1902,7,80
45
7065,"Birth of a Nation, The",Drama|War,1915,6,92
56
7243,Intolerance: Love's Struggle Throughout the Ages,Drama,1915,4,82

resources/total_cases.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
date,World,Afghanistan,Albania,Algeria,Andorra,Angola,Anguilla,Antigua and Barbuda,Argentina,Armenia,Aruba,Australia,Austria,Azerbaijan,Bahamas,Bahrain,Bangladesh,Barbados,Belarus,Belgium,Belize,Benin,Bermuda,Bhutan,Bolivia,Bonaire Sint Eustatius and Saba,Bosnia and Herzegovina,Botswana,Brazil,British Virgin Islands,Brunei,Bulgaria,Burkina Faso,Burundi,Cambodia,Cameroon,Canada,Cape Verde,Cayman Islands,Central African Republic,Chad,Chile,China,Colombia,Congo,Costa Rica,Cote d'Ivoire,Croatia,Cuba,Curacao,Cyprus,Czech Republic,Democratic Republic of Congo,Denmark,Djibouti,Dominica,Dominican Republic,Ecuador,Egypt,El Salvador,Equatorial Guinea,Eritrea,Estonia,Ethiopia,Faeroe Islands,Falkland Islands,Fiji,Finland,France,French Polynesia,Gabon,Gambia,Georgia,Germany,Ghana,Gibraltar,Greece,Greenland,Grenada,Guam,Guatemala,Guernsey,Guinea,Guinea-Bissau,Guyana,Haiti,Honduras,Hungary,Iceland,India,Indonesia,International,Iran,Iraq,Ireland,Isle of Man,Israel,Italy,Jamaica,Japan,Jersey,Jordan,Kazakhstan,Kenya,Kosovo,Kuwait,Kyrgyzstan,Laos,Latvia,Lebanon,Liberia,Libya,Liechtenstein,Lithuania,Luxembourg,Macedonia,Madagascar,Malawi,Malaysia,Maldives,Mali,Malta,Mauritania,Mauritius,Mexico,Moldova,Monaco,Mongolia,Montenegro,Montserrat,Morocco,Mozambique,Myanmar,Namibia,Nepal,Netherlands,New Caledonia,New Zealand,Nicaragua,Niger,Nigeria,Northern Mariana Islands,Norway,Oman,Pakistan,Palestine,Panama,Papua New Guinea,Paraguay,Peru,Philippines,Poland,Portugal,Puerto Rico,Qatar,Romania,Russia,Rwanda,Saint Kitts and Nevis,Saint Lucia,Saint Vincent and the Grenadines,San Marino,Sao Tome and Principe,Saudi Arabia,Senegal,Serbia,Seychelles,Sierra Leone,Singapore,Sint Maarten (Dutch part),Slovakia,Slovenia,Somalia,South Africa,South Korea,South Sudan,Spain,Sri Lanka,Sudan,Suriname,Swaziland,Sweden,Switzerland,Syria,Taiwan,Tanzania,Thailand,Timor,Togo,Trinidad and Tobago,Tunisia,Turkey,Turks and Caicos Islands,Uganda,Ukraine,United Arab Emirates,United Kingdom,United States,United States Virgin Islands,Uruguay,Uzbekistan,Vatican,Venezuela,Vietnam,Zambia,Zimbabwe
2-
2019-12-31,27,0,,0,,,,,,0,,0,0,0,,0,,,0,0,,,,,,,,,0,,,,,,0,,0,,,,,,27,,,,,0,,,,0,,0,,,0,0,0,,,,0,,,,,0,0,,,,0,0,,,0,,,,,,,,,,,,0,0,0,0,0,0,0,,0,0,,0,,,,,,0,,,,0,,,,0,0,0,,,0,,,,,,0,,0,,,,,,,,0,0,,0,,,0,,0,0,0,,,,,,0,,,,0,0,0,,,,,0,,,,,,,0,,,,,,0,,0,0,,,,0,0,,0,,0,,,,,,,,,0,0,0,,,,,,0,,
32
2020-01-01,27,0,,0,,,,,,0,,0,0,0,,0,,,0,0,,,,,,,,,0,,,,,,0,,0,,,,,,27,,,,,0,,,,0,,0,,,0,0,0,,,,0,,,,,0,0,,,,0,0,,,0,,,,,,,,,,,,0,0,0,0,0,0,0,,0,0,,0,,,,,,0,,,,0,,,,0,0,0,,,0,,,,,,0,,0,,,,,,,,0,0,,0,,,0,,0,0,0,,,,,,0,,,,0,0,0,,,,,0,,,,,,,0,,,,,,0,,0,0,,,,0,0,,0,,0,,,,,,,,,0,0,0,,,,,,0,,
43
2020-01-02,27,0,,0,,,,,,0,,0,0,0,,0,,,0,0,,,,,,,,,0,,,,,,0,,0,,,,,,27,,,,,0,,,,0,,0,,,0,0,0,,,,0,,,,,0,0,,,,0,0,,,0,,,,,,,,,,,,0,0,0,0,0,0,0,,0,0,,0,,,,,,0,,,,0,,,,0,0,0,,,0,,,,,,0,,0,,,,,,,,0,0,,0,,,0,,0,0,0,,,,,,0,,,,0,0,0,,,,,0,,,,,,,0,,,,,,0,,0,0,,,,0,0,,0,,0,,,,,,,,,0,0,0,,,,,,0,,
54
2020-01-03,44,0,,0,,,,,,0,,0,0,0,,0,,,0,0,,,,,,,,,0,,,,,,0,,0,,,,,,44,,,,,0,,,,0,,0,,,0,0,0,,,,0,,,,,0,0,,,,0,0,,,0,,,,,,,,,,,,0,0,0,0,0,0,0,,0,0,,0,,,,,,0,,,,0,,,,0,0,0,,,0,,,,,,0,,0,,,,,,,,0,0,,0,,,0,,0,0,0,,,,,,0,,,,0,0,0,,,,,0,,,,,,,0,,,,,,0,,0,0,,,,0,0,,0,,0,,,,,,,,,0,0,0,,,,,,0,,
5+
2019-12-31,27,0,,0,,,,,,0,,0,0,0,,0,,,0,0,,,,,,,,,0,,,,,,0,,0,,,,,,27,,,,,0,,,,0,,0,,,0,0,0,,,,0,,,,,0,0,,,,0,0,,,0,,,,,,,,,,,,0,0,0,0,0,0,0,,0,0,,0,,,,,,0,,,,0,,,,0,0,0,,,0,,,,,,0,,0,,,,,,,,0,0,,0,,,0,,0,0,0,,,,,,0,,,,0,0,0,,,,,0,,,,,,,0,,,,,,0,,0,0,,,,0,0,,0,,0,,,,,,,,,0,0,0,,,,,,0,,
66
2020-01-04,44,0,,0,,,,,,0,,0,0,0,,0,,,0,0,,,,,,,,,0,,,,,,0,,0,,,,,,44,,,,,0,,,,0,,0,,,0,0,0,,,,0,,,,,0,0,,,,0,0,,,0,,,,,,,,,,,,0,0,0,0,0,0,0,,0,0,,0,,,,,,0,,,,0,,,,0,0,0,,,0,,,,,,0,,0,,,,,,,,0,0,,0,,,0,,0,0,0,,,,,,0,,,,0,0,0,,,,,0,,,,,,,0,,,,,,0,,0,0,,,,0,0,,0,,0,,,,,,,,,0,0,0,,,,,,0,,
77
2020-01-05,59,0,,0,,,,,,0,,0,0,0,,0,,,0,0,,,,,,,,,0,,,,,,0,,0,,,,,,59,,,,,0,,,,0,,0,,,0,0,0,,,,0,,,,,0,0,,,,0,0,,,0,,,,,,,,,,,,0,0,0,0,0,0,0,,0,0,,0,,,,,,0,,,,0,,,,0,0,0,,,0,,,,,,0,,0,,,,,,,,0,0,,0,,,0,,0,0,0,,,,,,0,,,,0,0,0,,,,,0,,,,,,,0,,,,,,0,,0,0,,,,0,0,,0,,0,,,,,,,,,0,0,0,,,,,,0,,
88
2020-01-06,59,0,,0,,,,,,0,,0,0,0,,0,,,0,0,,,,,,,,,0,,,,,,0,,0,,,,,,59,,,,,0,,,,0,,0,,,0,0,0,,,,0,,,,,0,0,,,,0,0,,,0,,,,,,,,,,,,0,0,0,0,0,0,0,,0,0,,0,,,,,,0,,,,0,,,,0,0,0,,,0,,,,,,0,,0,,,,,,,,0,0,,0,,,0,,0,0,0,,,,,,0,,,,0,0,0,,,,,0,,,,,,,0,,,,,,0,,0,0,,,,0,0,,0,,0,,,,,,,,,0,0,0,,,,,,0,,

src/main/scala/org/apache/java/learning.java

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.apache.java;
22

3+
import java.util.LinkedList;
4+
import java.util.List;
5+
36
class home{
47
int a ;
58
String x;
@@ -17,6 +20,10 @@ public String toString(){
1720
}
1821
public class learning {
1922
public static void main(String args[]) {
23+
List<String> alist = new LinkedList<String>();
24+
alist.add("hello");
25+
System.out.println(String.join(",",alist));
26+
2027
home h1 = new home(1,"hello");
2128
home h2 = new home(2,"world");
2229
System.out.println(h1);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.apache.java.mastering.test;
2+
3+
// 1,2,3,4,5,6,7,8
4+
//key = 7
5+
class unsortedsearch{
6+
7+
public int ussearch(int[] a ,int lw , int hi , int key){
8+
while (lw <=hi){
9+
if(a[lw] == key || a[hi] == key){
10+
return (a[lw] == key)?lw : hi;
11+
}else
12+
{
13+
lw++;
14+
hi--;
15+
}
16+
}
17+
return -1;
18+
}
19+
}
20+
21+
public class searching {
22+
public static void main(String args[]){
23+
int[] a = {1,2,13,4,65,6,87,8};
24+
unsortedsearch obj = new unsortedsearch();
25+
System.out.println(obj.ussearch(a,0,a.length-1,87));
26+
27+
}
28+
}

src/main/scala/org/apache/scala/basics/allaboutscala/functions.scala

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ object functions extends App {
6767
def sqrroot(x: Int) = x * x
6868

6969
println("************************************** cbn cbv *************************")
70+
// https://stackoverflow.com/a/13337382/5773418
71+
// call-by-value functions compute the passed-in expression's value before calling the function, thus the same value is accessed every time. Instead, call-by-name functions recompute the passed-in expression's value every time it is accessed
7072
cbn(System.nanoTime())
7173
cbv(System.nanoTime())
7274

src/main/scala/org/apache/scala/basics/allaboutscala/mutablecollections.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ object mutablecollections extends App {
2929
println(aarraybuffer)
3030

3131
println("************************************** Set *************************")
32-
val aset = Set(1,2,3)
32+
val aset = Set(1,2,3,3)
3333
aset += 5
3434
println(aset)
3535

src/main/scala/org/apache/scala/basics/oops/abstractdata.scala

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ object abstractdata extends App {
88

99
// Abstract class with constructor
1010
// And the constructor contain two arguments
11+
12+
1113
abstract class myauthor(name: String,
1214
topic: String)
1315
{

src/main/scala/org/apache/scala/basics/oops/baseobj.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ object baseobj extends App {
1616

1717
//class combines the fields and methods(member function which defines actions) into a single unit.
1818
//Constructors are used to initializing the object’s state.
19-
// constructor contains a collection of statements that are executed at the time of Object creation.
19+
//constructor contains a collection of statements that are executed at the time of Object creation.
2020
class person(name: String, age: Int)
2121
//This is a constructor . Every single instance must be consturcted by passing in these 2 parms.
2222
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.apache.scala.consolidated.advanced
2+
3+
object closures {
4+
5+
def main(args: Array[String]) = {
6+
// Scala Closures are functions which uses one or more free variables and the return value of this function
7+
// is dependent of these variable.
8+
9+
// The free variables are defined outside of the Closure Function and is not included as a parameter of this function.
10+
// So the difference between a closure function and a normal function is the free variable.
11+
// A free variable is any kind of variable which is not defined within the function and not passed as the parameter of the function.
12+
val freevar = 10;
13+
def asum(a: Int) = {
14+
a + freevar
15+
}
16+
17+
println(asum(10))
18+
19+
}
20+
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.apache.scala.consolidated.advanced
2+
3+
object currying {
4+
def main(args: Array[String]) = {
5+
println("**************************************Currying*************************")
6+
// Scala Function Currying
7+
// it is a technique of transforming a function that takes multiple arguments into a function that takes a single argument.
8+
9+
def formatter(x: String)(y: Double) = x.format(y)
10+
11+
val sevenpie = formatter("%7.2f")(_)
12+
val threepie = formatter("%3.2f")(_)
13+
14+
System.out.println(sevenpie(Math.PI))
15+
System.out.println(threepie(Math.PI))
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package org.apache.scala.basics.allaboutscala
1+
package org.apache.scala.consolidated.advanced
2+
23
import scala.concurrent.Future
4+
import scala.util.{Failure, Success}
35
import scala.concurrent.ExecutionContext.Implicits.global
4-
import scala.util.{Success, Failure}
56

67
object futures extends App {
78
// Futures are the standard mechanism for writing multithreaded code in Scala.
@@ -12,7 +13,9 @@ object futures extends App {
1213
}
1314

1415
addnum(5,10).onComplete{
15-
case Success(n) => println(n)
16-
case Failure(e)=> println(e)
16+
case Success(n) => println("Hello"+ n)
17+
case Failure(e)=> println("Pello"+e)
1718
}
1819
}
20+
21+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.apache.scala.consolidated.collections
2+
3+
object collectionfunctions extends App {
4+
5+
// https://www.bigocheatsheet.com/img/big-o-cheat-sheet-poster.png
6+
// Array List
7+
// Access the ith element θ(1) θ(i)
8+
// Delete the ith element θ(n) θ(i)
9+
// Insert an element at i θ(n) θ(i)
10+
// Reverse θ(n) θ(n)
11+
// Concatenate (length m,n) θ(n+m) θ(n)
12+
// Count the elements θ(1) θ(n)
13+
val donuts: List[String] = List("Plain Donut 1", "Plain Donut 2", "Strawberry Donut", "Plain Donut 3", "Glazed Donut")
14+
println("************************************** drop *************************")
15+
// Drop n elements
16+
println(donuts.drop(2))
17+
18+
println("************************************** drop While *************************")
19+
// The code below shows how to use the dropWhile method to drop elements from the Donut sequence whose donut names start with the letter P.
20+
// The dropWhile method conveniently removes the first two elements, namely, Plain Donut 1 and Plain Donut 2. Since the first letter of the third element (Strawberry Donut) starts with the character 'S',
21+
// our predicate function no longer holds true. As a result, the "dropping" iteration stops at the third element, and we end up with all the remaining elements starting from the Strawberry Donut element itself - that is, Strawberry Donut, Plain Donut 3 and Glazed Donut
22+
println(donuts.dropWhile(_.charAt(0) == 'P'))
23+
24+
println("************************************** exists *************************")
25+
println(donuts.exists(_.contains("Plain")))
26+
27+
println("************************************** filter *************************")
28+
println(donuts.filter(_.contains("Plain")))
29+
println(donuts.filterNot(_.contains("Plain")))
30+
31+
println("************************************** find *************************")
32+
println(donuts.find(_.contains("Donut")).getOrElse("Boom"))
33+
34+
println("************************************** Fold *************************")
35+
// Fold will have a accumulator
36+
val alist = List(1, 2, 3, 4)
37+
println(alist.fold(0)(_ + _))
38+
39+
println(s"All donuts = ${donuts.fold("")((acc, s) => acc + s + " Donut ")}")
40+
val p = donuts.fold("")((acc, x) => {
41+
acc + x
42+
})
43+
println(p)
44+
45+
println("************************************** Slice *************************")
46+
println(donuts.slice(2, 3))
47+
48+
println("************************************** Transpose *************************")
49+
// transpose requires all collections have the same size
50+
val donuts1: Seq[String] = Seq("Plain Donut", "Strawberry Donut", "Glazed Donut")
51+
val prices: Seq[Double] = Seq(1.50, 2.0, 2.50)
52+
val donutslist = List(donuts1, prices)
53+
println(donutslist)
54+
println(donutslist.transpose)
55+
56+
println("************************************** Zip and unzip *************************")
57+
val zipval = donuts1.zip(prices)
58+
println(zipval)
59+
val unzipval = zipval.unzip
60+
println(unzipval._1)
61+
println(unzipval._2)
62+
63+
println("************************************** Zip withIndex *************************")
64+
println(donuts1.zipWithIndex)
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.apache.scala.consolidated.collections
2+
3+
object collectionseq extends App {
4+
// List , Array and vector are from Seq
5+
val aseq = Seq(1, 3, 3, 2, 1)
6+
println(aseq)
7+
// List(1, 3, 3, 2, 1) --> It will be printed as list only
8+
9+
//Ranges -It is a sequence of Int
10+
val arange: Seq[Int] = 1 to 5
11+
println("Range" + arange)
12+
13+
// List
14+
// Maintains order of elemetns and follow LIFO
15+
// Can have dups
16+
val mlist = List(1, 2, 3, 4)
17+
val prepend = 0 +: mlist :+ 5
18+
println("Append & Prepend" + prepend)
19+
20+
println(prepend.mkString("|"))
21+
22+
//Array - Same as simple Java array
23+
// They are mutable
24+
// Indexing is fast
25+
// interoprable with Java Arrays
26+
27+
val nums = Array(1, 2, 3, 4)
28+
val emptydim = Array.ofDim[Int](5)
29+
emptydim.foreach(println)
30+
31+
// array and seq - they are connected
32+
val numseq: Seq[Int] = nums //Implicit Conversions
33+
println(numseq)
34+
35+
36+
// Vectors
37+
// fast element addition
38+
// good performance for very large size -
39+
// It provides random access of elements. It is good for large collection of elements.
40+
val vectorseq: Vector[Int] = Vector(1, 2, 3, 4)
41+
println(vectorseq)
42+
43+
// SET
44+
// It is used to store unique elements in the set. It does not maintain any order for storing elements.
45+
val setval: Set[Int] = Set(1, 2, 3, 5, 3)
46+
println("setval" + setval)
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package org.apache.scala.consolidated.collections
2+
3+
import scala.collection.immutable.ListSet
4+
import scala.collection.mutable
5+
import scala.collection.mutable.ListBuffer
6+
7+
object immutablecollections extends App {
8+
9+
println("************************************** List *************************")
10+
val alist = List(1, 2, 3, 4, 5)
11+
val blist = List(5, 6, 68, 7)
12+
var clist = alist ::: blist
13+
println(clist)
14+
println("Remove list" + clist.filter(_ != 4))
15+
// List(1, 2, 3, 4, 5, 5, 6, 68, 7)
16+
// List is designed to be immutable hence do not make it mutable
17+
// Note that this operation has a complexity of O(n)-O(N) means in proportion to the number of items.. If you need this operation frequently, or for long lists, consider using another data type (e.g. a ListBuffer).
18+
var alistbuffer = new ListBuffer[Int]
19+
alistbuffer = alistbuffer ++ clist
20+
println(alistbuffer)
21+
// Maintains order of elemetns and follow LIFO
22+
// Can have dups
23+
val mlist = List(1, 2, 3, 4)
24+
val prepend = 0 +: mlist :+ 5
25+
println("Append & Prepend" + prepend)
26+
println(prepend.mkString("|"))
27+
28+
println("**************************************List set *************************")
29+
// No immutable data
30+
// Stores in Reverse order , LIFO
31+
val alistset = ListSet(1, 2, 4, 4, 5)
32+
println(alistset)
33+
34+
println("**************************************List Map *************************")
35+
val alistmap: mutable.ListMap[String, String] = mutable.ListMap("a" -> "b", "c" -> "c")
36+
println(alistmap)
37+
38+
println("**************************************Hash Map *************************")
39+
var ahashmap: mutable.HashMap[String, String] = mutable.HashMap("a" -> "b", "c" -> "c")
40+
println(ahashmap)
41+
42+
println("**************************************Seq *************************")
43+
// List --> Singly linked list , List --> Doubly linked list
44+
val aseq = Seq("a", "b", 1)
45+
println(aseq)
46+
val flist = List("a", "b", 1)
47+
println(flist)
48+
// List(1, 3, 3, 2, 1) --> It will be printed as list only
49+
// array and seq - they are connected
50+
val numseq: Seq[Int] = nums //Implicit Conversions
51+
println(numseq)
52+
53+
println("**************************************Range *************************")
54+
//Ranges -It is a sequence of Int
55+
val arange: Seq[Int] = 1 to 5
56+
println("Range" + arange)
57+
58+
println("**************************************Array *************************")
59+
//Array - Same as simple Java array
60+
// They are mutable
61+
// Indexing is fast
62+
// interoprable with Java Arrays
63+
64+
val nums = Array(1, 2, 3, 4)
65+
val emptydim = Array.ofDim[Int](5)
66+
emptydim.foreach(println)
67+
68+
println("**************************************Vectors *************************")
69+
// fast element addition
70+
// good performance for very large size -
71+
// It provides random access of elements. It is good for large collection of elements.
72+
val vectorseq: Vector[Int] = Vector(1, 2, 3, 4)
73+
println(vectorseq)
74+
75+
println("**************************************SET *************************")
76+
// It is used to store unique elements in the set. It does not maintain any order for storing elements.
77+
val setval: Set[Int] = Set(1, 2, 3, 5, 3)
78+
println("setval" + setval)
79+
80+
}

0 commit comments

Comments
 (0)