String originalString = "hello"; int length = 10; char padChar = '*'; String paddedString = StringUtils.rightPad(originalString, length, padChar); System.out.println(paddedString);
hello*****
String originalString = "abc"; int length = 2; char padChar = '*'; String paddedString = StringUtils.rightPad(originalString, length, padChar); System.out.println(paddedString);
abcIn this example, the original string "abc" is already longer than the specified length of 2, so no padding is added. Overall, StringUtils is a helpful class in the org.apache.commons.lang package library for common string manipulations in Java.