tags:

views:

546

answers:

1

With Java 1.5, the contains(CharSequence s) method was added to the String class. This method

Returns true if and only if this string contains the specified sequence of char values.

How would you do this in versions of Java prior to 1.5, specifically in version 1.4.2?

+2  A: 

To get the same effect as String.contains(substring) in Java 1.4, you can use the following snippet:

String.indexOf(substring) != -1
Paul Wagland
contains() does exactly this, so no difference.
Bozho
I have updated the answer to explain what I think the asker is asking... in particular, contains doesn't exist in Java 1.4, and that is, by my understanding of the question, where tasmohan is trying to compile.
Paul Wagland
yes.. exactly i tried to asked what you thought.thanks for answer.
@Paul - there is one minor nit. The `contains` method takes any `CharSequence` as an argument, but `indexOf` requires a `String` (or a `char`).
Stephen C
@Stephen - yes, you are correct, in the case where you really want to use a 'CharSequence' you should do 'substring.toString()'.
Paul Wagland
Updated the answer again, based on the question now clearly asking what was intended.
Paul Wagland