在Scala ListSet中,takeWhile()
隻要滿足指定的條件,就可以使用“方法”從列表中查找元素。
函數定義: def takeWhile(p: (A) => Boolean): ListSet[A]
返回類型: It returns the elements from the list as long as the stated condition is satisfied.
範例1:
// Scala program of takeWhile()
// method
import scala.collection.immutable._
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a list
val m1 = ListSet(1, 2, 3, 4, 5, 7)
// Applying takeWhile method
val result = m1.takeWhile(_ > 3)
// Displays output
println(result)
}
}
輸出:
ListSet(4, 5, 7)
範例2:
// Scala program of takeWhile()
// method
import scala.collection.immutable._
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a list
val m1 = ListSet(1, 2, 3, 4, 5, 7)
// Applying takeWhile method
val result = m1.takeWhile(_ > 7)
// Displays output
println(result)
}
}
輸出:
ListSet()
相關用法
- Scala List takeWhile()用法及代碼示例
- Scala ListSet max()用法及代碼示例
- Scala ListSet min()用法及代碼示例
- Scala ListSet sum()用法及代碼示例
- Scala ListSet filterNot()用法及代碼示例
- Scala ListSet count()用法及代碼示例
- Scala ListSet isEmpty()用法及代碼示例
- Scala ListSet filter()用法及代碼示例
- Scala ListSet exists()用法及代碼示例
- Scala ListSet find()用法及代碼示例
- Scala ListSet size()用法及代碼示例
- Scala ListSet product()用法及代碼示例
- Scala Listset apply()用法及代碼示例
- Scala Map min()用法及代碼示例
注:本文由純淨天空篩選整理自IshwarGupta大神的英文原創作品 Scala ListSet takeWhile() method with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。