Skip to content

Instantly share code, notes, and snippets.

@msbaek
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save msbaek/c8481d9c047766860df9 to your computer and use it in GitHub Desktop.

Select an option

Save msbaek/c8481d9c047766860df9 to your computer and use it in GitHub Desktop.
some list methods and usages
// the empty list
List()
Nil
// 원소를 갖는 리스트 생성
List("Cool", "tools", "rule")
// 3개의 값으로 새로운 List 생성
val thrill = "Will" :: "fill" :: "until" :: Nil
// 2개의 list concatenate
List("a", "b") ::: List("c", "d")
// list에서 2번째 원소 반환
thrill(2)
thrill.count(s => s.length == 4)
thrill.count(_.length == 4)
thrill.drop(2)
thrill.dropRight(2)
thrill.exists(_ == "until")
thrill.filter(_.length == 4)
thrill.forall(_.endsWith("l"))
thrill.foreach(print(_))
thrill.head
thrill.init
thrill.isEmpty
thrill.last
thrill.length
thrill.map(_ + "y")
thrill.mkString(",")
thrill.reverse
thrill.sortBy(_.charAt(0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment