Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

Scala Programming: Check a given list is a palindrome or not

Scala Programming List Exercise-17 with Solution

Write a Scala program to check a given list is a palindrome or not.

Sample Solution:

Scala Code:

object Scala_List {
  
  def is_Palindrome[A](list_nums: List[A]):Boolean = {
    list_nums == list_nums.reverse
}
     
   def main(args: Array[String]): Unit = {
         println("Result: " + is_Palindrome(List(1,2,3,4,3,2,1)));
         println("Result: " + is_Palindrome(List(1,2,3)));
       }
}

Sample Output:

Result: true
Result: false

Scala Code Editor :

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Scala program to reverse a given list.
Next: Write a Scala program to flatten a given List of Lists, nested list structure.

What is the difficulty level of this exercise?