Let\'s say I have a couple variable and I want to format them so they\'re all aligned, but the variables are different lengths. For example:
String a = \"abc
You can achieve it as below-
String a = "abcdef"; String b = "abcdefhijk"; double price = 4.56; System.out.println(String.format("%-10s %-10.2f", a, price)); System.out.println(String.format("%-10s %-10.2f", b, price));
output:
abcdef 4.56 abcdefhijk 4.56