Padding to 10 characters:
String.format("%10s", "foo").replace(' ', '*');
String.format("%-10s", "bar").replace(' ', '*');
String.format("%10s", "longer than 10 chars").replace(' ', '*');
output:
*******foo
bar*******
longer*than*10*chars
Display '*' for characters of password:
String password = "secret123";
String padded = String.format("%"+password.length()+"s", "").replace(' ', '*');
output has the same length as the password string:
secret123
*********