Used Scala immutable List

Recursively adding elements to it instead of Java's mutable list