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 Top answer 1 of 12
41
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
2 of 12
26
The StringBuilder class does not have a contains() method, but String does. So you can use StringBuilder to build a string by using toString(). Then call contains() on it, to check if it contains that character or string.
Example:
stringBuilder.toString().contains(characterYouWantToCheck)
03:12
#69 Java String contains() Method – Check if a String Has a ...
01:00
Quick Java Tip: How to Use the String.contains Method in Just 60 ...
09:34
How to use the String Builder Class in Java - YouTube
03:50
contains string method in java | java tutorial | @mscoder - YouTube
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 } }
Reddit
reddit.com › r/learnprogramming › (java) how can i check if a stringbuilder contains a string?
r/learnprogramming on Reddit: (Java) How can I check if a StringBuilder contains a string?
November 5, 2016 -
I'm currently stuck on this problem:(
Thanks in advance
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 ...
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.
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).
Tutorialspoint
tutorialspoint.com › java › lang › stringbuilder_indexof_str.htm
Java StringBuilder indexOf() Method
The Java StringBuilder indexOf() method is used to retrieve the index of the first occurrence of the specified character in a String or StringBuilder, and the method is case-sensitive, which means that the string "A" and "a" are two different values.