Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

String contains problem  RSS feed

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am on JDK 1.4 and I would like to know if there is a substitute for contains method found in String class in JDK 1.5. TIA.
 
Marshal
Posts: 58421
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try the indexOf("abc") method. If you get a number it is in there; if it is not found you get -1. But what is wrong with the contains() method?

CR
 
Balachandran Paranjothimani
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing is wrong with contains. The deployment is targeted for WAS 6.0 which supports J2EE 1.4. String contains method is available only in Java 5.

Your code works. I did see that contains has the same implementation but just overlooked to pass the string to be tested. Thanks.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!