Align left and right
In this chapter you will learn:
Right and left align strings
public class Main {
public static void main(String args[]) {
String format = "|%1$-10s|%2$10s|%3$-20s|\n";
System.out.format(format, "A", "AA", "AAA");
System.out.format(format, "B", "", "BBBBB");
System.out.format(format, "C", "CCCCC", "CCCCCCCC");
/*from j ava 2 s .c om*/
String ex[] = { "E", "java2s.com", "E" };
System.out.format(String.format(format, (Object[]) ex));
}
}
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » String