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?
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- React - JavaScript Library
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework