In Java within Android Studio, you can implement the padRight feature as follows:
public class StringUtils {
public static String padRight(String input, int length, char paddingChar) {
if (input.length() >= length) {
return input;
} else {
StringBuilder sb = new StringBuilder(input);
while (sb.length() < length) {
sb.append(paddingChar);
}
return sb.toString();
}
}
public static void main(String[] args) {
String text = "Hello";
String paddedText = padRight(text, 10, '-');
System.out.println(paddedText); // Output: "Hello-----"
}
}
The above padRight function in the StringUtils class appends the paddingChar character to the right side of the input string until it reaches the specified length. If the input is already greater than or equal to the length, the original text is returned without modification.
To use this code in Android Studio, you can add the StringUtils class to your project and call the padRight function like any other method. As shown in the main method, you can use it with the desired parameters. Adapt the usage of the function according to your project needs.