pad String - Java java.lang

Java examples for java.lang:String Pad

Description

pad String

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String source = "java2s.com";
        System.out.println(padString(source));
    }/*from w  w w  .j a va2  s . c  o m*/

    private static String padString(String source) {
        char paddingChar = ' ';
        int size = 16;
        int x = source.length() % size;
        int padLength = size - x;

        for (int i = 0; i < padLength; i++) {
            source += paddingChar;
        }
        return source;
    }
}

Related Tutorials