Here you can find the source of formatRow(String[] values, int[] sizes)
Parameter | Description |
---|---|
values | the values |
sizes | the sizes |
public static String formatRow(String[] values, int[] sizes)
//package com.java2s; public class Main { private static final String SPACES = " "; /**/*from w w w .j a v a 2 s. c om*/ * Format row. * * @param values * the values * @param sizes * the sizes * * @return the string */ public static String formatRow(String[] values, int[] sizes) { return formatRow(" ", values, sizes); } /** * Format row. * * @param prefix * the prefix * @param values * the values * @param sizes * the sizes * * @return the string */ public static String formatRow(String prefix, String[] values, int[] sizes) { StringBuffer sb = new StringBuffer(); sb.append(prefix); for (int i = 0; i < sizes.length; i++) { if (i != 0) { sb.append(" "); } sb.append(fixLength(values[i], sizes[i])); } return sb.toString(); } /** * Fix length. * * @param str * the str * @param len * the len * * @return the string */ public static String fixLength(String str, int len) { if (str != null) { str = str + SPACES; } else { str = SPACES; } return str.substring(0, len); } }