Hur jag Scala:r del 2 😛

[java]
import java.util._;

object Main {
def main(args : Array[String]) = {

val arrayOfPersons = Array(
new Person("Peter" , "Lindblom"),
new Person("Patrik", "Von Lidl"),
new Person("Philip", "Philipsson"),
new Person("Trygve", "Scala"),
new Person("Phil", "Almighty")
);

arrayOfPersons.foreach(person => ListOfPersons addPerson person);

print(ListOfPersons);

}
}

class Person(var firstName:String, var lastName:String ) {
override def toString() : String = "Name: " + firstName +"\t" + lastName+ "\n";
}

object ListOfPersons {
private var listOfPersons = new ArrayList[Person];

def addPerson (person : Person ) = {
listOfPersons add person
}

def getPersons = {
listOfPersons toArray
}

override def toString : String = {
var outputBuilder = new StringBuilder();

outputBuilder.append("ListOfPerson\n");
outputBuilder.append("————————\n");
getPersons.foreach(person => outputBuilder.append(person));

outputBuilder toString
}
}

[/java]

[bash]
ListOfPerson
————————
Name: Peter Lindblom
Name: Patrik Von Lidl
Name: Philip Philipsson
Name: Trygve Scala
Name: Phil Almighty

[/bash]