You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ko/overviews/collections/conversions-between-java-and-scala-collections.md
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
layout: overview-large
3
-
title: Conversions Between Java and Scala Collections
3
+
title: 자바와 스칼라 컬렉션간 변환
4
4
5
5
disqus: true
6
6
@@ -9,9 +9,9 @@ num: 17
9
9
language: ko
10
10
---
11
11
12
-
Like Scala, Java also has a rich collections library. There are many similarities between the two. For instance, both libraries know iterators, iterables, sets, maps, and sequences. But there are also important differences. In particular, the Scala libraries put much more emphasis on immutable collections, and provide many more operations that transform a collection into a new one.
12
+
스칼라와 마찬가지로 자바 또한 풍부한 컬렉션 라이브러리를 제공한다. 둘 사이에는 반복자(iterator), 반복가능(iterable), 집합(set), 맵(map)과 열(sequence) 등 유사한 점이 많지만 중요한 차이점 또한 존재하는데, 특히 스칼라 라이브러리의 경우 변경 불가능한 컬렉션을 훨씬 더 강조하거나 더욱 많은 컬렉션간 변환 연산을 지원하는 점이 그러하다.
13
13
14
-
Sometimes you might need to pass from one collection framework to the other. For instance, you might want to access to an existing Java collection, as if it was a Scala collection. Or you might want to pass one of Scala's collections to a Java method that expects its Java counterpart. It is quite easy to do this, because Scala offers implicit conversions between all the major collection types in the [JavaConversions](http://www.scala-lang.org/api/{{ site.scala-version }}/scala/collection/JavaConversions$.html) object. In particular, you will find bidirectional conversions between the following types.
14
+
때때로 한 컬렉션 프레임워크를 다른 것으로 대체해야 할 경우가 생긴다. 예를 들어, 이미 존재하는 자바 컬렉션을 마치 스칼라 컬렉션처럼 접근하거나, 자바 컬렉션을 인자로 받는 자바 메소드에 스칼라 컬렉션을 넘기고 싶을 수 있다. 이러한 작업은 모든 주요 컬렉션간의 암시적 변환을 제공하는 [JavaConversions](http://www.scala-lang.org/api/{{ site.scala-version }}/scala/collection/JavaConversions$.html) 객체를 통해 손쉽게 가능하다. 구체적으로 다음과 같은 양방향 변환등을 찾을 수 있다.
15
15
16
16
17
17
Iterator <=> java.util.Iterator
@@ -23,12 +23,12 @@ Sometimes you might need to pass from one collection framework to the other. For
To enable these conversions, simply import them from the [JavaConversions](http://www.scala-lang.org/api/{{ site.scala-version }}/scala/collection/JavaConversions$.html) object:
26
+
이러한 변환을 활성화하려면 단순히 [JavaConversions](http://www.scala-lang.org/api/{{ site.scala-version }}/scala/collection/JavaConversions$.html) 객체에서 임포트하면 된다:
27
27
28
28
scala> import collection.JavaConversions._
29
29
import collection.JavaConversions._
30
30
31
-
You have now automatic conversions between Scala collections and their corresponding Java collections.
31
+
이제 자동적으로 스칼라 컬렉션과 이에 대응하는 자바 컬렉션간의 변환이 가능하다.
32
32
33
33
scala> import collection.mutable._
34
34
import collection.mutable._
@@ -39,16 +39,16 @@ You have now automatic conversions between Scala collections and their correspon
Internally, these conversion work by setting up a "wrapper" object that forwards all operations to the underlying collection object. So collections are never copied when converting between Java and Scala. An interesting property is that if you do a round-trip conversion from, say a Java type to its corresponding Scala type, and back to the same Java type, you end up with the identical collection object you have started with.
42
+
내부적으로, 이러한 변환은 원본 컬렉션 객체로 모든 연산을 전달하는 "래퍼(wrapper)" 객체를 통해 이루어진다. 따라서 자바와 스칼라간 변환에 있어 컬렉션은 절대 복사되지 않는다. 흥미로운 것은 왕복 변환이 일어날 때, 예를 들어 자바에서 스칼라로, 다시 자바로 변환되는 경우, 처음과 정확히 동일한 컬렉션 객체가 된다는 점이다.
43
43
44
-
The are some other common Scala collections than can also be converted to Java types, but which to not have a corresponding conversion in the other sense. These are:
44
+
스칼라에서 자바로 변환은 가능하지만 반대로는 불가능한 공통 스칼라 컬렉션도 있다:
45
45
46
46
Seq => java.util.List
47
47
mutable.Seq => java.utl.List
48
48
Set => java.util.Set
49
49
Map => java.util.Map
50
50
51
-
Because Java does not distinguish between mutable and immutable collections in their type, a conversion from, say, `scala.immutable.List` will yield a `java.util.List`, where all mutation operations throw an "UnsupportedOperationException". Here's an example:
51
+
자바는 변경 가능한 컬렉션과 변경 불가능한 컬렉션을 자료형으로 구분하지 않기 때문에, `scala.immutable.List`는 `java.util.List`로 변환되지만 모든 변경 연산은 "UnsupportedOperationException"을 발생시킨다. 예제를 보자:
0 commit comments