Q:

Write a Scala program to check whether two String objects contain the same data

0

Write a Scala program to check whether two String objects contain the same data.

All Answers

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

object Scala_String {  
  def test(str1: String, str2: String): Boolean = {
    str1.equals(str2)   
  }
  def main(args: Array[String]): Unit = {
        val columnist1 = "Stephen Edwin King";
        val columnist2 = "Stephen Edwin  King";
        val columnist3 = "Stephen Edwin King";

        // Are any of the above Strings equal to one another?
        val equals1 = test(columnist1,columnist2)
        val equals2 = test(columnist1,columnist3)
        // Display the results of the equality checks.
        System.out.println(""" + columnist1 + "" equals "" +
            columnist2 + ""? " + equals1);
        System.out.println(""" + columnist1 + "" equals "" +
            columnist3 + ""? " + equals2);
      }
}

Sample Output:

"Stephen Edwin King" equals "Stephen Edwin  King"? false
"Stephen Edwin King" equals "Stephen Edwin King"? true

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