add Pad to String - Java java.lang

Java examples for java.lang:String Pad

Description

add Pad to String

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String str = "java2s.com";
        int size = 2;
        String pad = "java2s.com";
        StringBuilder builder = new StringBuilder();
        addPad(str, size, pad, builder);
    }//from w  w  w.j  a  v a  2 s .  c o  m

    public static void addPad(String str, int size, String pad,
            StringBuilder builder) {
        for (int i = 0; i < size - str.length(); i++) {
            builder.append(pad);
        }
    }
}

Related Tutorials