ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Scala String contentEquals() Method with Example

Here, we will learn about the contentEquals() method of String in Scala. It is used to check whether the string and string Buffer contain the same values or not. We will see its working, syntax and example.
Submitted by Shivang Yadav, on February 04, 2021

String is an immutable collection that stores sequences of characters.

String contentEquals() Method

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!
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.