

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
In this java tutorial, we explore how to use the string.contains() method to determine if one string includes another string in java. We provide code examples and explanations.
What you will learn
Typology: Study notes
1 / 2
This page cannot be seen from the preview
Don't miss anything!
Java Program Output
Java Program Output
public class Example { public static void main(String[] args) { String str1 = "apple"; String str2 = "pp"; boolean result = str1.contains(str2); System.out.println("Does str1 contains str2? " + result); } } Does str1 contains str2? true public class Example { public static void main(String[] args) { String str1 = "apple"; String str2 = "kk"; boolean result = str1.contains(str2); System.out.println("Does str1 contains str2? " + result); } } Does str1 contains str2? false
Conclusion In this Java Tutorial, we learned how to check if a string contains another string in Java. ✦ Java Tutorial Java String Operations ✦ Java String ✦ Java String Operations ✦ Java - Print String to Console ✦ Java - Read String from Console ✦ Java - Concatente two Strings ✦ Java - Check if Strings are Equal ✦ Java - Find Index of First Occurrence of Substring ✦ Java - Find Index of Nth Occurrence of Substring ✦ Java - Replace First Occurrence of Substring ✦ Java - Replace All Occurrences of Substring ✦ Java - Reverse a String ✦ Java - Split String ✦ Java - Trim String