Create a String with a fixed length

From CodeCodex

Implementations[edit]

Java[edit]

 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];
        java.util.Arrays.fill(chars, fillChar);
        return new String(chars);
    }
}

Ruby[edit]

size = 25
puts '>' + 'X' * size + '<'
puts '>' + ' ' * size + '<'

Tcl[edit]

puts ">[string repeat X 25]<"
puts ">[string repeat " " 25]<"