Forget String.subString()

When ever you have to extract some chars from string then you se String.subString() method but apache has given org.apache.commons.lang3.StringUtils  class which is much better than string suppose when you have a string “aabbccddefghdz” and you want all chars that  comes after last occurence of d then you should use

System.out.println(StringUtils.substringAfterLast(“aabbccddefghdzac”, “d”));

so the result will be zac.

There are many more methods in StringUtils which you should use rather than string if you want to make performance good

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s