StringUtils is Operations on String that are null safe. Snipset code below was a my code history.

//when i was in collage
String result="putracode":
if(data ==null && data.length>0 ){
result=data;
}
//First Time in Job
String result= (data ==null && data.length>0 ? data ; "putracode");
//And Now
String result=StringUtils.defaultIfBlank(data,"putracode");

Look More Simple.. 😀
StringUtils Helpme todo some operatations like :

  • IsEmpty/IsBlank – checks if a String contains text
  • Trim/Strip – removes leading and trailing whitespace
  • Substring/Left/Right/Mid – null-safe substring extractions
  • SubstringBefore/SubstringAfter/SubstringBetween – substring extraction relative to other strings
  • Split/Join – splits a String into an array of substrings and vice versa
  • Plugins 2Remove/Delete – removes part of a String
  • Replace/Overlay – Searches a String and replaces one String with another
  • Chomp/Chop – removes the last part of a String
  • AppendIfMissing – appends a suffix to the end of the String if not present
  • PrependIfMissing – prepends a prefix to the start of the String if not present
  • LeftPad/RightPad/Center/Repeat – pads a String
  • And More you can look at JavaDOC

Let see an example in the code snippet below:

And here are the results of our code snippet above:

 

Visit My Repository for full code
<a href=”https://github.com/srigalamilitan/PC-COMMONS-LANG3″ rel=”attachment wp-att-67″><img class=”alignleft size-thumbnail wp-image-67″ src=”https://putracode.com/wp-content/uploads/2016/02/showimage-150×150.png” alt=”showimage” width=”150″ height=”150″ /></a>

Tagged with: