Scala – Maps




// Scala - Maps 
object Demo {
  val mymap : Map[Int, String] =
    Map(801 -> "max", 802 -> "Tom", 804 -> "July");
  val mymap2 : Map[Int, String] =
    Map(805 -> "lua");
	def main(args: Array[String]) {
		println(mymap);
		println(mymap(801));
		println(mymap.keys);
		println(mymap.values);
		println(mymap.isEmpty);
		
		mymap.keys.foreach { key =>
		  println("key " + key);
		  println("Value "+ mymap(key));
		  
		}
		
		println(mymap.contains(801000));
		println(mymap ++ mymap2);
		println(mymap.size);
	}
}

/*
output:
Map(801 -> max, 802 -> Tom, 804 -> July)
max
Set(801, 802, 804)
MapLike.DefaultValuesIterable(max, Tom, July)
false
key 801
Value max
key 802
Value Tom
key 804
Value July
false
Map(801 -> max, 802 -> Tom, 804 -> July, 805 -> lua)
3


*/

Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*