Check Permutation in Scala The problem is: Given two strings, write a method to decide if one is a permutation of the other. I wrote the following code in scala, may I know any other optimization one?

def checkpermutation(str1:String, str2:String): Boolean=(str1, str2) match {
   case (a,b) if a==b =&gt; true
   case (a,b) if a.length() !=b.length() =&gt;false
   case (a,b) if a.toList.sorted.mkString== a.toList.sorted.mkString =&gt; true
   case _ =&gt;false
 }
There is no need to use matchers for this check. A logical expression would be enough:

def checkpermutation2(a:String, b:String): Boolean = {
  def sorted(s: String) = s.sorted.mkString
  (a == b) || (a.length == b.length &amp;&amp; sorted(a) == sorted(b))
}