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 OverflowBaeldung
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 provides a flеxiblе and еfficiеnt way to manipulatе strings. In some cases, we nееd to chеck whеthеr a StringBuildеr objеct contains a specific character.
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)
Baeldung
baeldung.com › home › java › java string › java string.contains()
Java String.contains() | Baeldung
April 11, 2025 - • Java String.contains() (current ... String.toUpperCase() • Java String.trim() • Java String.valueOf() The method contains() checks if a String contains another String....
Hyperskill
hyperskill.org › university › java › java-stringbuilder
Java StringBuilder
December 4, 2024 - Strings in Java are immutable which means that once created, a string cannot be changed. If we want to modify the content of a string object, we should create a new string. This may not be the best way when we perform a lot of modifications because each operation creates a new object, which is bad for performance. Fortunately, there is a special class named StringBuilder that is used to create mutable string objects.
Baeldung
baeldung.com › home › java › java string › how to convert string to stringbuilder and vice versa in java
How to Convert String to StringBuilder and Vice Versa in Java | Baeldung
April 7, 2025 - Working with Strings is a fundamental aspect of Java programming. StringBuilder is an often-used utility for String manipulations, such as concatenation, reversing, etc.
Medium
medium.com › @itworldeducation › string-handling-a42502c50337
STRING HANDLING. Spring Boot Application | by It World Education | Medium
December 1, 2024 - In some Spring Boot applications, you might need to work with multi-line strings (e.g., for emails, reports, or template rendering). Using StringBuilder or StringJoiner can help in handling multi-line content.
GeeksforGeeks
geeksforgeeks.org › java › stringbuilder-indexof-method-in-java-with-examples
StringBuilder indexOf() method in Java with Examples - GeeksforGeeks
April 18, 2023 - // Java program to demonstrate // the indexOf() Method. class GFG { public static void main(String[] args) { // create a StringBuilder object // with a String pass as parameter StringBuilder str = new StringBuilder("GeeksForGeeks"); // print string System.out.println("String contains = " + str); // get index of string For int index = str.indexOf("For"); // print results System.out.println("index of string 'For' = " + index); } } Output: String contains = GeeksForGeeks index of string 'For' = 5 ·
Stack Overflow
stackoverflow.com › questions › 60174770 › spring-boot-jpa-criterialbuilder-check-if-string-contains-expressionstring
Spring Boot & JPA: CriterialBuilder check if String contains Expression<String> - Stack Overflow
February 11, 2020 - public class AthleteSpecification implements Specification<Athlete> { private String gender; public AthleteSpecification(String gender) { super(); this.gender = gender; } @Override public Predicate toPredicate(Root<Athlete> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Predicate p = cb.disjunction(); if (this.gender == null) { return cb.conjunction(); } else { Expression<Boolean> isMaleOrFemaleorDivers; if (this.gender != null) { // This is a working solution but not nice Expression<Boolean> isMale = cb.equal(root.get("gender"), gender.contains("M") ?
Baeldung
baeldung.com › home › java › java string › all about string in java
All About String in Java | Baeldung
September 28, 2023 - Get started with understanding multi-threaded applications with our Java Concurrency guide: ... Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:
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).
Baeldung
baeldung.com › home › java › java string › reuse stringbuilder for efficiency
Reuse StringBuilder for Efficiency | Baeldung
January 8, 2024 - Reusing StringBuilder instances can help optimize an application’s memory usage and speed. Instantiating new objects can be expensive in terms of memory and CPU usage. Since strings are immutable in Java, using a StringBuilder to concatenate different strings usually avoids unnecessary object creation.
Java Guides
javaguides.net › 2018 › 08 › java-stringbuilder-class-api-guide.html
Java StringBuilder: Basics, Methods, Examples, Performance Tips
August 4, 2023 - Java StringBuffer: Methods, Examples, and Performance Tips ... In this course, you will learn Spring Core, Spring Boot 3, REST API, Spring MVC, WebFlux, Spring Security, Spring Data JPA, Docker, Thymeleaf & Building Projects.
Stack Overflow
stackoverflow.com › questions › 63745951 › spring-boot-and-java-8-is-there-a-way-to-build-a-string-dynamically
Spring boot and java 8: Is there a way to build a string dynamically? - Stack Overflow
just use a StringBuilder or simple string concatenation to build up your query string · Springs UriComponentsBuilder JavaDoc provides a more structured way of building a query string and might be more familiar to your JPA based solution · using RestTemplates allows to pass a conditionally filled Map representing your request parameters ·