right Pad String - Java java.lang

Java examples for java.lang:String Pad

Description

right Pad String

Demo Code


//package com.java2s;

public class Main {


    public static String rightPad(String str, int size, String pad) {
        StringBuilder builder = new StringBuilder();
        builder.append(str);//from  w  ww  . jav a 2s  .  c om
        addPad(str, size, pad, builder);
        return builder.substring(0, size);
    }

    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