[Solved] String Formatting for a list

You can use String format for this. String format = “%-10s |%10s |%10s |%10s |%10s\n”; System.out.printf(format, values[0], values[1], values[2], values[3], values[4]); above code will give the expected result. EDIT: Using StringUtils for formatting. String result = StringUtils.EMPTY; result = StringUtils.center(values[0], 10) + ‘|’ + StringUtils.center(values[1], 10) + ‘|’+ StringUtils.center(values[2], 15) + ‘|’ + StringUtils.center(values[3], 15) … Read more