File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 323
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: 3742

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46334
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: 24199

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

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: finding a particular string in string type
It's not a secret anymore!