Java contentEquals() Method
-- Learning Not Just Technology, But Dreams!
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
Java Tutorial
Java Tutorial Java Introduction Java Development Environment Setup Java Basic Syntax Java Comments Java Objects and Classes Java Basic Data Types Java Variable Types Java Variable Naming Rules Java Modifier Types Java Operators Java Loop Structures β for, while and doβ¦while Java Conditional Statements β ifβ¦else Java switch case Statement Java Number & Math Classes Java Character Class Java String Class Java StringBuffer and StringBuilder Classes Java Arrays Java Date and Time Java Regular Expressions Java Methods Java Constructors Java Stream, File and IO Java Scanner Class Java Exception Handling
Java Object-Oriented
Java Inheritance Java Override/Overload Java Polymorphism Java Abstract Classes Java Encapsulation Java Interfaces Java Enums Java Packages Java Reflection
Java Advanced Tutorial
Java Data Structures Java Collections Framework Java ArrayList Java LinkedList Java HashSet Java HashMap Java Iterator Java Object Java NIO Files Java Generics Java Serialization Java Networking Java Sending Email Java Multithreading Java Applet Basics Java Documentation Comments Java Examples Java 8 New Features Java MySQL Connection Java 9 New Features Java Quiz Java Common Libraries
Java StringBuffer and StringBuilder Classes
Explore In-Depth
- Web Services
- Scripting
- Computer Science
- Software
- Development Tools
- Programming Languages
- Web Design and Development
- Scripting Languages
- Web Service
- Programming
Java contentEquals() Method
The contentEquals() method is used to compare this string with the specified StringBuffer.
Syntax
public boolean contentEquals(StringBuffer sb)
Parameters
- sb -- The StringBuffer to be compared with the string.
Return Value
Returns true if the string represents the same character sequence as the specified StringBuffer; otherwise, returns false.
Example
public class Test {
public static void main(String args[]) {
String str1 = "String1";
String str2 = "String2";
StringBuffer str3 = new StringBuffer( "String1");
boolean result = str1.contentEquals( str3 );
System.out.println(result);
result = str2.contentEquals( str3 );
System.out.println(result);
}
}
The result of the above program execution is:
truefalse
YouTip