The Artima Developer Community
Sponsored Link

Java Buzz Forum
String contains() and indexOf() Example - Check String for SubString

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Javin Paul

Posts: 1090
Nickname: javinpaul
Registered: Jan, 2012

Javin Paul is Java Programmer working on Finance domain.
String contains() and indexOf() Example - Check String for SubString Posted: Oct 18, 2012 6:32 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Javin Paul.
Original Post: String contains() and indexOf() Example - Check String for SubString
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
Latest Java Buzz Posts
Latest Java Buzz Posts by Javin Paul
Latest Posts From Java67

Advertisement


Some time you want to check if one String contains another String or SubString or not e.g. "HelloWorld" contains "Hello" and "World" SubString. There are many ways to check SubString in String in Java e.g. contains(), indexOf() or matches() method of java.lang.String class. In our last article we have seen how to use matches method of String class with regular expression and In this article we will see example of contains() and indexOf() method to check any String or SubString in Java. contains and indexOf method are defined in java.lang.String class and used to check if String contains a particular SubString or not, only difference between contains() and indexOf() method is that, contains is added in Java 5 along with String matches() method while indexOf() is as old as equals(), hashCode and compareTo(). Another difference between contains() and indexOf() method is that contains() return boolean value e.g. true if String contains SubString and false if String doesn't contains SubString but indexOf() return int value, which is actually index of SubString i.e. starting location. indexOf() return -1 if source String does not contain SubString in Java.
Read more ยป

Read: String contains() and indexOf() Example - Check String for SubString

Topic: How to convert Hexadecimal to Decimal, Binary and Octal in Java program - Example Previous Topic   Next Topic Topic: Things Great Engineers (almost) Never Say

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use