wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes finding a particular string in string type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "finding a particular string in string type" Watch "finding a particular string in string type" New topic

finding a particular string in string type

kundan varma
Ranch Hand

Joined: Mar 08, 2004
Posts: 322
Hi All,
I need to find whether a particular string like "kundan" exist in a line or not. What is the best way to solve this in java?
Can somebody give a example.
Thanks and regards,

Failures are practice shoots for success.
Joanne Neal

Joined: Aug 05, 2005
Posts: 3429

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38031
Have you never tried the contains method in String? It only works in J5 and 6, however.
Rakesh Kumar
Ranch Hand

Joined: May 30, 2006
Posts: 63
welcome to javaranch discussion boards

let 's' be the the string coressponding theline,then
s.indexOf("kundan") will give the index of 1st occurence of the string"kundan".

Parambir Singh
Ranch Hand

Joined: Sep 05, 2004
Posts: 40

And if "kundan" is not present, it will return -1.

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

Advanced? I think not. Moving to Java in General (Beginner).

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link: http://aspose.com/file-tools
subject: finding a particular string in string type
Similar Threads
Why HashSet is adding duplicates even if I get same hashcode for two obects & passes true fromequals
Passed SCEA part 2/3 with 70
using plus inside StringBuffer
using plus inside StringBuffer
Accessing session object from getConnection method