package org.kodejava.commons.lang;
import org.apache.commons.lang3.StringUtils;
public class StringReverseDemo {
public static void main(String[] args) {
// We have an original string here that we'll need to reverse.
String words = "The quick brown fox jumps over the lazy dog";
// Using StringUtils.reverse we can reverse the string letter by letter.
String reversed = StringUtils.reverse(words);
// Now we want to reverse per word, we can use
// StringUtils.reverseDelimited() method to do this.
String delimitedReverse = StringUtils.reverseDelimited(words, ' ');
// Print out the result
System.out.println("Original: " + words);
System.out.println("Reversed: " + reversed);
System.out.println("Delimited Reverse: " + delimitedReverse);
}
}
Here is the result:
Original: The quick brown fox jumps over the lazy dog
Reversed: god yzal eht revo spmuj xof nworb kciuq ehT
Delimited Reverse: dog lazy the over jumps fox brown quick The
Maven Dependencies
<!-- https://search.maven.org/remotecontent?filepath=org/apache/commons/commons-lang3/3.12.0/commons-lang3-3.12.0.jar -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
Latest posts by Wayan (see all)
- How do I convert Map to JSON and vice versa using Jackson? - June 12, 2022
- How do I find Java version? - March 21, 2022
- How do I convert CSV to JSON string using Jackson? - February 13, 2022