esuslogo
 [To advertise Java(tm) Events here, contact joris@esus.com!]
banner

Java™
by example!






New @ Esus.com


  gb  In-house search engine for better results!

  gb  Get updates with the esus.com
newsletter!









  Home 
 Browse Categories 
 Ask a Java Question 
 Help 
  For Java Tips & Tricks, subscribe to the esus.com newsletter!
Search Java Q&A, Links, API's:   adv 

How do I determine whether a String contains another String?
Use java.lang.String.indexOf(String) to check if one string contains another. indexOf() will return -1 if the string is not found and the starting index of the string if it is found.


 
String a = "Some text";
String b = "text";

if (a.indexOf(b) != -1) {
System.out.println("String a contains String b, starting at position " + a.indexOf(b));
} else {
System.out.println("String a does not contain String b");
}




Further Information
Author of answer: Edgecrusher

Comments
Comments to this answer are only viewable by members. Login or become a member!





Terms of Service | Privacy Policy | Contact

Copyright © 2000-2003 Esus.com - All Rights Reserved 
Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. Esus.com is independent of Sun Microsystems, Inc. All other trademarks are the sole property of their respective owners.