f_
frhyme.code
•java•⏱ 약 1분 소요

Scala - Collection

  • scala의 collection, Array, List, Set, Map에 대해서 간단하게 정리하였습니다.
// S
object HelloWorld {
  def main(args: Array[String]) {
    val arr1:Array[Int] = Array(2, 4, 6, 8);
    val lst1:List[Int] = List(1, 2, 3, 4)
    System.out.println(lst1.length); // 4
    System.out.println(arr1.length); // 4

    val set1:Set[Int] = Set(1, 2, 3, 5);
    System.out.println(set1.size); // 4
    System.out.println(set1.contains(4)); // false

    val map1:Map[Int, Char] = Map(1 -> 'A', 2 -> 'B');
    System.out.println(map1); // Map(1 -> A, 2 -> B)
    System.out.println(map1.keys); // Set(1, 2)
    System.out.println(map1.values); // Iterable(A, B)   
  }
}
GitHub에서 이 글의 마크다운 원본 보기 & 수정 제안src/content/posts/2021-01-23-scala03_collection

💡RELATED ARTICLES · 함께 읽으면 좋은 연관 포스트

글 주소가 클립보드에 복사되었습니다.