To check if two StringBuilder objects are equal, the code is as follows −
Example
using System;
using System.Text;
public class Demo {
public static void Main(String[] args){
StringBuilder strBuilder1 = new StringBuilder("Tim");
StringBuilder strBuilder2 = new StringBuilder("Tom");
StringBuilder strBuilder3 = new StringBuilder();
strBuilder2 = strBuilder3;
Console.WriteLine("Is StringBuilder3 equal to StringBuilder2? = "+strBuilder3.Equals(strBuilder2));
}
}Output
This will produce the following output −
Is StringBuilder3 equal to StringBuilder2? = True
Example
Let us see another example −
using System;
using System.Text;
public class Demo {
public static void Main(String[] args){
StringBuilder strBuilder1 = new StringBuilder("Jacob");
StringBuilder strBuilder2 = new StringBuilder("Jacob");
Console.WriteLine("Is StringBuilder1 equal to StringBuilder2? = "+strBuilder2.Equals(strBuilder1));
}
}Output
This will produce the following output −
Is StringBuilder1 equal to StringBuilder2? = True