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 code of the program is given below:
The output of the program is given below:
The original String: Hi, How R YOU? The reversed string: ?UOY R woH ,iH The delimited Reverse string: YOU? R How Hi,
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.