Home »
Scala
Scala String contentEquals() Method
By IncludeHelp Last updated : October 21, 2024
Description and Usage
The contentEquals() method on strings is used to compare the contents of a string and a string buffer. It checks for the equality of both.
Syntax
string_Name.contentEquals(StringBuffer string_buffer)
Parameters
The method accepts a single parameter which a stringBuffer to be checked for equality with the string.
Return Value
It returns a Boolean value which is the result of the comparison operation.
Example 1
object myObject {
def main(args: Array[String]) {
val myString = "Scala"
val myStringBuffer = new StringBuffer("Scala")
val hasSameContent = myString.contentEquals(myStringBuffer)
if(hasSameContent)
println("The string and stringBuffer have the same content!")
else
println("The string and stringBuffer have different content!")
}
}
Output
The string and stringBuffer have the same content!
Example 2
object myObject {
def main(args: Array[String]) {
val myString = "Scala"
val myStringBuffer = new StringBuffer("Scala programming language")
val hasSameContent = myString.contentEquals(myStringBuffer)
if(hasSameContent)
println("The string and stringBuffer have same content!")
else
println("The string and stringBuffer have different content!")
}
}
Output
The string and stringBuffer have different content!