1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
import scala.collection.jcl._
object Test extends Application {
testMap
testSet
}
object testMap {
def test(m1: Map[Int, Int]) {
try {
m1.put(10, 20)
val m2 = m1.clone()
m1.put(20, 30)
println("m1="+m1)
println("m2="+m2)
println("m1 == m2 is "+ (m1 == m2))
println()
}
catch {
case e: Exception =>
println(e); println()
}
}
def test1(m1: Map[Int, Int]) {
try {
m1.put(10, 20)
val m2 = m1.clone()
m1.put(20, 30)
println("m1.size > m2.size is "+ (m1.size > m2.size))
println()
}
catch {
case e: Exception =>
println(e); println()
}
}
test(new HashMap[Int, Int])
test(new LinkedHashMap[Int, Int])
// NB. class IdentityHashMap makes no guarantees as to the order
// of the map; in particular, it does not guarantee that the order
// will remain constant over time (see Java API docs).
//test1(new IdentityHashMap[Int, Int])
test(new TreeMap[Int, Int])
test(new WeakHashMap[Int, Int])
test1(new IdentityHashMap[Int, Int])
}
object testSet {
def test(m1: Set[Int]) {
m1.add(10)
val m2 = m1.clone()
m1.add(20)
println("m1="+m1)
println("m2="+m2)
println("m1 == m2 is "+ (m1 == m2))
println()
}
test(new HashSet[Int])
test(new LinkedHashSet[Int])
test(new TreeSet[Int])
}
|