Created
September 2, 2013 07:58
-
-
Save f81/6410298 to your computer and use it in GitHub Desktop.
第8章:Scalaのコレクション(Seq, Set, Map)入門 ref: http://qiita.com/f81@github/items/dc79819d23ce4889d552
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> val numbers = Set(1, 2, 3) | |
numbers: scala.collection.immutable.Set[Int] = Set(1, 2, 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> import scala.collection.mutable.Set | |
import scala.collection.mutable.Set | |
scala> var numbers = Set(1, 2, 3) | |
numbers: scala.collection.mutable.Set[Int] = Set(1, 2, 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> val numbers = List(1, 2, 3) | |
numbers: List[Int] = List(1, 2, 3) | |
scala> val numbers = 1 :: 2 :: 3 :: Nil | |
numbers: List[Int] = List(1, 2, 3) | |
scala> val numbers = 1 :: (2 :: (3 :: Nil)) | |
numbers: List[Int] = List(1, 2, 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> val numbers = List(1, 2, 3) | |
numbers: List[Int] = List(1, 2, 3) | |
scala> numbers.tail.head | |
res5: Int = 2 | |
scala> numbers.tail.tail.head | |
res6: Int = 3 | |
scala> numbers.tail.tail.isEmpty | |
res7: Boolean = false | |
scala> numbers.tail.isEmpty | |
res8: Boolean = false | |
scala> numbers.tail.tail.tail.isEmpty | |
res9: Boolean = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> val numbers = Set(1, 2, 3) | |
numbers: scala.collection.mutable.Set[Int] = Set(1, 2, 3) | |
scala> numbers.contains(1) | |
res15: Boolean = true | |
scala> numbers.contains(4) | |
res16: Boolean = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> val colors = Map(1 -> "red", 2 -> "blue", 3 -> "black") | |
colors: scala.collection.immutable.Map[Int,String] = Map(1 -> red, 2 -> blue, 3 -> black | |
scala> colors(1) | |
res13: String = red | |
scala> colors(3) | |
res14: String = black |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment