diff --git a/stdlib.ipr b/stdlib.ipr
index 30c354500c5..693c766ab77 100644
--- a/stdlib.ipr
+++ b/stdlib.ipr
@@ -27,6 +27,9 @@
+
+
+
diff --git a/stdlib/ktSrc/JavaUtil.kt b/stdlib/ktSrc/JavaUtil.kt
index 46cbda926e0..cae1b643c5c 100644
--- a/stdlib/ktSrc/JavaUtil.kt
+++ b/stdlib/ktSrc/JavaUtil.kt
@@ -11,28 +11,13 @@ val Collection<*>.empty : Boolean
get() = isEmpty()
/** Returns a new ArrayList with a variable number of initial elements */
-inline fun arrayList(vararg values: T) : ArrayList {
- val answer = ArrayList()
- for (v in values)
- answer.add(v)
- return answer;
-}
+inline fun arrayList(vararg values: T) : ArrayList = values.to(ArrayList(values.size))
/** Returns a new LinkedList with a variable number of initial elements */
-inline fun linkedList(vararg values: T) : LinkedList {
- val answer = LinkedList()
- for (v in values)
- answer.add(v)
- return answer;
-}
+inline fun linkedList(vararg values: T) : LinkedList = values.to(LinkedList())
/** Returns a new HashSet with a variable number of initial elements */
-inline fun hashSet(vararg values: T) : HashSet {
- val answer = HashSet()
- for (v in values)
- answer.add(v)
- return answer;
-}
+inline fun hashSet(vararg values: T) : HashSet = values.to(HashSet(values.size))
/** Returns true if any elements in the collection match the given predicate */
inline fun java.lang.Iterable.any(predicate: fun(T): Boolean) : Boolean {
@@ -123,6 +108,13 @@ inline fun java.util.Collection.map(result: Collection = ArrayList<
return result
}
+// TODO would be nice to not have to write extension methods for Array, Iterable and Iterator
+
+inline fun > Array.to(result: C) : C {
+ for (elem in this)
+ result.add(elem)
+ return result
+}
inline fun > java.lang.Iterable.to(result: C) : C {
for (elem in this)