Write a Scala program to check whether a list contains a sublist.
object Scala_List { def test_sublist[A](list1:List[A], list2:List[A]):Boolean = { list1.forall(list2.contains) } def main(args: Array[String]): Unit = { println(test_sublist(List(1,2), List(1,2,3,4))) println(test_sublist(List(1,2), List(1,3,4,2))) println(test_sublist(List(1,2), List(1,3,4))) } }
Sample Output:
true true false
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output: