Skip to content

Instantly share code, notes, and snippets.

@rupeshtr78
Created October 28, 2020 17:25
Show Gist options
  • Save rupeshtr78/640e1a0f4be0a429419a01da3d0b242e to your computer and use it in GitHub Desktop.
Save rupeshtr78/640e1a0f4be0a429419a01da3d0b242e to your computer and use it in GitHub Desktop.
import scala.collection.immutable.{HashMap, ListMap, ListSet, Queue}
import scala.collection.{LinearSeq, SortedSet, mutable}
val trav = Traversable(1, 2, 3)
val iter = Iterable("x", "y", "z")
val map = Map("x" -> 24, "y" -> 25, "z" -> 26)
val numArray = Array[Int](1, 2, 3, 4, 5)
val numList = List[Int](1, 2, 3, 4, 5)
val vector: Vector[Int] = Vector(1,2,3)
val set = Set("color",1,1) //Set(color, 1)
val sortedSet = SortedSet("hello", "world") //TreeSet(hello, world)
val buffer = mutable.Buffer(1, 2, 'z') //ArrayBuffer(1, 2, 122)
val indexedSeq = IndexedSeq(1.0, 2.0) //Vector(1.0, 2.0)
val linearSeq= LinearSeq('a', 'b', 'c')
//Maps
var hashMapName = HashMap("key1"->"value1", "key2"->"value2", "key3"->"value3")
var listMap = ListMap("Rice"->"100","Wheat"->"50","Gram"->"500")
val listSet = ListSet(1, 2, 3, 4)
val aTuple = (2, "hello, Scala")
var queue = Queue(200,5,6,2,3,9,5,2,5)
var stream2 = (1 to 10).toStream //Stream(1, ?)
var stream = 100 #:: 200 #:: 85 #:: Stream.empty //Stream(100, ?)
var firstElement = stream2.head // 1
//Option
val myFirstOption: Option[Int] = Some(4) //Some(4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment