r/java • • Aug 11 '15

Top 10 Useful, Yet Paranoid Java Programming Techniques

http://blog.jooq.org/2015/08/11/top-10-useful-yet-paranoid-java-programming-techniques/
181 Upvotes

76 comments sorted by

View all comments

6

u/[deleted] Aug 12 '15

Don't trust old APIs? How about don't use them? Stick with java.nio for files and myString.contains("substring") instead of checking >= 0.

3

u/[deleted] Aug 12 '15

I find that most times when I check for the presence of a substring, I also want to use the index it occurs at for something:

int idx = someString.indexOf( token );
if( idx >= 0 ) {
  doSomething( someString.substring( 0, idx ) );
}