The StringBuilder class does not have a contains() method, but it does have an indexOf() method. The indexOf() method returns -1 when the substring is not found.

Example:

stringBuilder.indexOf(charactersYouWantToCheck) != -1
Answer from Simon Baars on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java string › check if a java stringbuilder object contains a character
Check If a Java StringBuilder Object Contains a Character | Baeldung
January 24, 2024 - Thе StringBuildеr class in Java is part of thе java.lang packagе and is usеd to crеatе mutablе sеquеncеs of charactеrs.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-string-contains-method-example
Java String contains() Method with Example - GeeksforGeeks
July 11, 2025 - This approach is used when we need to check if a String contains content from a StringBuilder. ... // Java program to check if a String // contains a substring constructed using StringBuilder public class StringBuilderExample { public static void main(String[] args) { String s1 = "Welcome to GFG"; StringBuilder s2 = new StringBuilder("GFG"); // Check if mainString contains substring System.out.println(s1.contains(s2)); // true } }
🌐
DEV Community
dev.to › rishabhtpt › java-string-contains-method-explained-with-examples-2957
Java String Contains Method Explained with Examples - DEV Community
September 2, 2025 - It is used to check if a sequence of characters exists inside a given string. If the string contains the specified sequence, the method returns true; otherwise, it returns false. Syntax: public boolean contains(CharSequence sequence) Parameter: ...
🌐
Baeldung
baeldung.com › home › java › java string › java string.contains()
Java String.contains() | Baeldung
April 11, 2025 - • Java String.contains() (current ... • Java String.trim() • Java String.valueOf() The method contains() checks if a String contains another String....
🌐
CodeGym
codegym.cc › java blog › strings in java › java string contains() method
Java String contains() Method
January 8, 2025 - In this example, the contains() method successfully identifies the sequence of characters in a StringBuilder, demonstrating its flexibility.
🌐
Codekru
codekru.com › home › java string contains() method
Java String contains() method - Codekru
June 12, 2022 - So, we can pass the objects of all of the normal classes into the contains() method arguments to check whether the string contains it or not. public class Codekru { public static void main(String[] args) { String str = "hello codekru"; String string = "codekru"; StringBuilder stringBuilder ...
Find elsewhere
🌐
TechVidvan
techvidvan.com › tutorials › stringbuilder-class-in-java
StringBuilder Class in Java with Examples - TechVidvan
July 22, 2024 - In Java, the StringBuilder class replaces the String class since it generates a mutable sequence of characters rather than an immutable one like the String Class does.
🌐
W3Schools
w3schools.com › java › ref_string_contains.asp
Java String contains() Method
The contains() method checks whether a string contains a sequence of characters. Returns true if the characters exist and false if not. ... The CharSequence interface is a readable sequence of char values, found in the java.lang package.
🌐
GeeksforGeeks
geeksforgeeks.org › java › stringbuilder-class-in-java-with-examples
StringBuilder Class in Java - GeeksforGeeks
StringBuilder is a mutable sequence of characters provided by the java.lang package. Unlike String, its contents can be modified without creating a new object for every operation.
Published: September 1, 2026
🌐
Tutorialspoint
tutorialspoint.com › java › lang › string_contains.htm
Java - String contains() Method
The Java String contains() method is used to check whether the current string contains the specified sequence. It returns the Boolean value, which is true if and only if the string contains the sequence of char values; false otherwise.
🌐
GeeksforGeeks
geeksforgeeks.org › java › stringbuilder-indexof-method-in-java-with-examples
StringBuilder indexOf() method in Java with Examples - GeeksforGeeks
April 18, 2023 - The indexOf(String str) method of StringBuilder class is the inbuilt method used to return the index within the String for first occurrence of passed substring as parameter.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › StringBuilder.html
StringBuilder (Java Platform SE 8 )
July 21, 2026 - For example, if z refers to a string builder object whose current contents are "start", then the method call z.append("le") would cause the string builder to contain "startle", whereas z.insert(4, "le") would alter the string builder to contain "starlet". In general, if sb refers to an instance of a StringBuilder, then sb.append(x) has the same effect as sb.insert(sb.length(), x).
🌐
Scaler
scaler.com › home › topics › java › stringbuilder in java with examples, methods and constructors
StringBuilder in Java with Examples, Methods, and Constructors - Scaler Topics
May 3, 2023 - Internally StringBuilder updates the capacity by (previouscapcity+1)*2. By default 16 bytes is the capacity of the StringBuilder when StringBuilder contains no elements.
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 493928 › why-stringbuilder-class-not-having-contains-method
Why StringBuilder class not having Contains method - Microsoft Q&A
July 28, 2021 - IMHO it's because you can do contains, startswith, endswith etc against .ToString() which keeps StringBuilder focused on it's original intent to build efficient strings.
🌐
ZetCode
zetcode.com › java › stringbuilder
Java StringBuilder - mutable Java strings with StringBuilder
StringBuilder is a mutable sequence of characters. StringBuilder is used when we want to modify Java strings in-place.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › lang › StringBuilder.html
StringBuilder (Java Platform SE 7 )
For example, if z refers to a string builder object whose current contents are "start", then the method call z.append("le") would cause the string builder to contain "startle", whereas z.insert(4, "le") would alter the string builder to contain "starlet". In general, if sb refers to an instance of a StringBuilder, then sb.append(x) has the same effect as sb.insert(sb.length(), x).