Q:

Write a Scala program to check whether a list contains a sublist

0

Write a Scala program to check whether a list contains a sublist.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now