Home »
Code Examples »
Scala Code Examples
Scala - How to use partition() method? Code Example
The code for How to use partition() method?
object Demo {
def main(args: Array[String]) = {
val nums = List(10, 20, 30, 40, 50, 60, 70)
// Using partition() method
// to get twice of each element.
val (result1, result2) = nums.partition(x=>{x % 3 == 0})
// printing results
println(result1)
println(result2)
}
}
/*
Output:
List(30, 60)
List(10, 20, 40, 50, 70)
*/
Code by IncludeHelp,
on August 13, 2022 20:51