progs/lecture1.scala
changeset 364 f1a6fa599d26
parent 361 f88b5cec2e5d
child 367 e6ae724255a8
equal deleted inserted replaced
363:e5c1d69cffa4 364:f1a6fa599d26
   520 // There are also a massive number of Scala tutorials on youtube
   520 // There are also a massive number of Scala tutorials on youtube
   521 // and there are tons of books and free material. Google is your 
   521 // and there are tons of books and free material. Google is your 
   522 // friend.
   522 // friend.
   523 
   523 
   524 
   524 
   525 
       
   526 
       
   527 
       
   528 // declarative 
       
   529 
       
   530 users.filter(_.email.endsWith("@gmail.com"))
       
   531 
       
   532 // imperative
       
   533 
       
   534 val result = ListBuffer[User]()
       
   535 for(user <- users) {
       
   536     if(user.email.endsWith("@gmail.com")) {
       
   537         result += user
       
   538     }
       
   539 }
       
   540 result.toList
       
   541 
       
   542 
       
   543 
       
   544 
       
   545 
       
   546 
       
   547