user218420
user218420

Reputation: 33

"contains(CharSequence s)" method in String class in JDK 1.4.2

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?

Upvotes: 3

Views: 18120

Answers (1)

Paul Wagland
Paul Wagland

Reputation: 29179

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

String.indexOf(substring) != -1

Upvotes: 15

Related Questions