Java tutorial
//package com.java2s; public class Main { private static String appendColumnSpaces(String value, int columnWidth) { StringBuilder builder = new StringBuilder(); int spaceCount; if (value == null) { builder.append("null"); spaceCount = columnWidth - 4; } else { builder.append(value); spaceCount = columnWidth - value.length(); } for (int i = 0; i < spaceCount; i++) { builder.append(" "); } return builder.toString(); } }