String Reverse Using StringUtils
In this example we are going to reverse a given string using StringUtils api. In this example we are reversing a string and the reversed string is delimited by a specific character.
The org.apache.commons.lang.StringUtils class extends Object class and defines certain words related to String handling such as null for null,"" for a zero-length string, ' ' for space characters, Charecter.isWhitespace(char) for whitespace and String.trim() for trim.
The methods used:
reverse(String str): This method is used to reverse the order of a buffered string. It returns a null value if no string is passed i.e StringUtils.reverse(null) = null or StringUtils.reverse("") = "" otherwise reverse order will returns e.g. StringUtils.reverse("bat") = "tab".
reverseDelimited(String str,char separatorChar): This method is used to reverse a String that is delimited by a specific character like "". The strings between the delimiters will not reverse. In this method "str" is string to reverse and "separatorChar" is the separator character.
The output of the program is given below: