Create a String with fixed length and filled with a specific characterTag(s): String/Number
About cookies on this site
We use cookies to collect and analyze information on site performance and usage,
to provide social media features and to enhance and customize content and advertisements.
public class StringFixedAndFilled {
public static void main(String argv[]) {
String s = ">" + fillString('X', 25) + "<";
System.out.println(s);
s = ">" + fillString(' ', 25) + "<";
System.out.println(s);
/*
output : >XXXXXXXXXXXXXXXXXXXXXXXXX<
> <
*/
}
public static String fillString(char fillChar, int count){
// creates a string of 'x' repeating characters
char[] chars = new char[count];
while (count>0) chars[--count] = fillChar;
return new String(chars);
}
}